简体   繁体   中英

How to add colour and legend in multiple line plot on ggplot without using melt from reshape package?

I am plotting two lines on same plot with sme x axis by following lines. i am implementing the lower line but unable to see colors and legend

ggplot(final, aes(x = Date)) + geom_line(aes(y = cocastock)) + geom_line(aes(y = procterstock))  + scale_color_manual(values = c(cocastock = '#008B00', procterstock = '#FFFFFF'))

also tried

ggplot(final, aes(x = Date)) + geom_line(aes(y = cocastock)) + geom_line(aes(y = procterstock))  + scale_color_manual(values = c('#008B00','#FFFFFF'))

but dosen't work

scale_colour_manual only works when you have specified colour in aes , hence you need:

ggplot(final, aes(x = Date)) + 
  geom_line(aes(y = cocastock, colour = "cocastock")) + 
  geom_line(aes(y = procterstock, colour = "procterstock"))  + 
  scale_color_manual(values = c(cocastock = '#008B00', procterstock = '#FFFFFF'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM