我想绘制一些线条并让它们在颜色和线型上有所区别。如果我单独区分颜色,那很好。如果我添加线型,第 14 组的线就会消失。
(ggplot2_2.1.0,R 版本 3.3.1)
library(ggplot2)
g <- paste("Group", 1:14)
group <- factor(rep(g, each=14), levels=g)
x <- rep(1:14, length.out=14*14)
y <- c(runif(14*13), rep(0.55, 14))
d <- data.frame(group, x, y, stringsAsFactors=FALSE)
# Next 2 lines work fine - check the legend for Group 14
ggplot(d, aes(x, y, color=group)) +
geom_line()
# Add linetype
ggplot(d, aes(x, y, color=group, linetype=group)) +
geom_line()
# Group 14 is invisible!
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?