如何通过ggplot更改图例中的线型

时间:2016-04-02 19:37:38

标签: r plot

我绘制了以下情节:

enter image description here

使用代码:

ggplot(decadevalue, aes(decade,group=1))+ 
geom_line(aes(y=decadevalue[,1],colour="black"),size=1.5,linetype = "dashed")+
geom_line(aes(y=decadevalue[,2],colour="#E69F00"),size=1.5,linetype = "twodash")+
geom_line(aes(y=decadevalue[,3],colour="#56B4E9"),size=1.5)+
geom_line(aes(y=decadevalue[,4],colour="#009E73"),size=1.5)+
geom_line(aes(y=decadevalue[,5],colour="#F0E442"),size=1.5)+
geom_line(aes(y=decadevalue[,6],colour="#0072B2"),size=1.5)+
geom_line(aes(y=decadevalue[,7],colour="#D55E00"),size=1.5)+
geom_line(aes(y=decadevalue[,8],colour="#CC79A7"),size=1.5)+
geom_line(aes(y=decadevalue[,9],colour="#000000"),size=1.5)+
geom_line(aes(y=decadevalue[,10],colour="#CC6666"),size=1.5,linetype = "dotted")+
ggtitle("Plot of Percentage of Motivations by Decade")+
xlab("Decade")+ ylab("Percentage")+
scale_colour_discrete(name="",labels=c(MI[9],MI[6],MI[4],MI[3],MI[10],MI[8],MI[7],MI[2],MI[5],MI[1]))+
scale_linetype_discrete(limits = c(rep("solid", 4),"dotted",rep("solid",2),"twodash","solid","dashed"))+
theme(axis.text.x = element_text(angle = 45, hjust = 1))

有人知道如何更改图例中相应的线型吗?

1 个答案:

答案 0 :(得分:0)

您可以使用scale_linetype_manual

scale_linetype_manual(values=c(1,1,1,1,2,3,2,3))+ 
...
...