更改密度图的图例中的值

时间:2015-02-28 20:34:40

标签: r ggplot2

如何将图例的值从“2”和“3”更改为“Solid”和“Dotted”?

library(ggplot2)

ggplot(mtcars) +
  geom_line(aes(x=mpg,y=cyl,linetype='2')) +
  geom_line(aes(x=mpg,y=disp,linetype='3')) + 
  scale_linetype_discrete(name = "Lines Types  aes") 

enter image description here

1 个答案:

答案 0 :(得分:1)

ggplot(mtcars) +
  geom_line(aes(x=mpg,y=cyl,linetype='2')) +
  geom_line(aes(x=mpg,y=disp,linetype='3')) + 
  scale_linetype_discrete(name = "Lines Types  aes", labels = c("Solid","Dotted"))