我试图将 ggplot 中的一行从破折号更改为虚线,但失败了,函数 scale_linetype_manual 不起作用。谁能帮我解决这个问题?
ggplot(d, aes(a,value)) +
geom_line(aes(color = series), size=2)+
scale_y_continuous(breaks=seq(-2.5, 2.5, 2.5)) +
coord_cartesian(ylim=c(-2.5, 2.5))+
scale_x_continuous(breaks=seq(-200, 2000, 1000)) +
scale_color_manual(values=c("#E69F00","#56B4E9", "#56B4E9")) +
scale_linetype_manual(values=c("twodash", "dotted", "dotted")) +
theme(legend.direction = 'vertical',
legend.position = 'right',
legend.key = element_rect(size = 7),
legend.key.size = unit(3, 'lines'))+
theme(panel.grid.major = element_blank(), text = element_text(size=30),
panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour =
"black"))+
geom_vline(xintercept=c(0), linetype="dotted", size=1.5)+
geom_rect(data=rect, aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax),
color="gray55",
alpha=0.4,
inherit.aes = FALSE)+
labs(x = "time [ms]",
y = "Amplitude [µV]",
color = "")
最佳答案
你的情节的“问题”是你没有映射审美 linetyppe
到一个变量。因此,您调用 scale_linetype_manual
没有效果。您应该将代码更改为
ggplot(d, aes(a,value)) +
geom_line(aes(color = series, linetype = series), size = 2) +
...
关于r - 使用 scale_linetype_manual 更改 ggplot 图中的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48261154/