使用ggplot2 R软件包,我制作了一个带有6条彩色线条的折线图(对应一个因子的6个水平),我想将其改为黑白图形,其中3条为黑色实线、虚线和点线,另外3条为灰色实线、虚线和点线。我尝试使用scale_linetype_manual()和scale_color_grey()函数,但是我无法混合灰色和黑色的点线。
这里是灰色选项的代码:
ggplot() +
geom_line(data = f[!is.na(f$fr),], aes(x=date2, y=fr, colour=locality, group=locality),
size = 1.0) +
scale_color_grey(start = 0, end = 0.9, guide="legend", name="Locality",
labels=c("a","b","c","d","e","f")) +
xlab("") +
ylab("") +
theme_bw() +
theme(legend.position = "top", panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "white"),
axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) +
facet_grid(.~year)
以下是带虚线的代码:
ggplot() +
geom_line(data = f[!is.na(f$fr),], aes(x=date2, y=fr, linetype=locality, group=locality),
size = 1.0) +
scale_linetype_manual(name="Locality",
values=c("solid", "dashed", "dotted", "dotdash", "longdash", "twodash"),
labels=c("a","b","c","d","e","f")) +
xlab("") +
ylab("") +
theme_bw()+
theme(legend.position = "top", panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "white"),
axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) +
facet_grid(.~year)
请问有没有人能帮我用一条实线的黑色线、一条虚线的黑色线、一条点线的黑色线、一条实线的灰色线等来制作这张图呢?