【发布时间】:2016-03-29 00:39:37
【问题描述】:
我在 R 中使用 ggplot2,并且有一个颜色(变量 1)和线型(变量 2)的手动刻度。两种类型的其中一个级别是相同的,我只是希望它出现在一条普通的行中,因此从 variable2 图例中消失。
请参阅下面的最少代码。
require(ggplot2)
data_0 <- expand.grid(x=1:2,
variable1=c("nothing", "A", "B"),
variable2=c("nothing", "positif", "negatif")
)
data <- subset(data_0, !((variable1=="nothing" & variable2 != "nothing") |
(variable2=="nothing" & variable1 != "nothing")))
data$y <- rep(1:5, each = 2)
ggplot(data=data, aes(x=x, y=y, colour = variable1, lty = variable2))+
geom_line(size=1.5)+
theme_bw()+
theme(legend.position="bottom")+
scale_linetype_manual(values = c(1,3,5))
【问题讨论】: