使用ggplot2 R软件包,我创建了一条带有6条彩色线条的线条图(指的是6个级别的因子),我想用黑色和白色来改变它,制作3条黑色实线,虚线和虚线以及3个灰色实体,虚线和虚线.我尝试使用scale_linetype_manual()和scale_color_grey(),但我无法混合灰色和黑色虚线.
这里是scale灰色选项的代码:
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)
所以..有人可以帮助我用一条黑色实线,一条黑色虚线,一条黑色虚线,一条灰色实线等创建相同的图.
地图既colour
和linetype
,并设定手动刻度.
d <- data.frame(locality = rep(letters[1:6], each = 2), x = 1:2, y = rep(1:6, each = 2)) ggplot(d, aes(x = x, y = y,colour = locality, linetype = locality)) + geom_line() + theme_bw() + scale_color_manual(name = "Locality", values = c('black', 'black', 'black', 'grey', 'grey', 'grey'), labels = c("a","b","c","d","e","f")) + scale_linetype_manual(name = "Locality", values = c("solid", "dashed", "dotted", "solid", "dashed", "dotted"), labels = c("a","b","c","d","e","f"))