r - How can I add guide to ggplot2? -


this question has answer here:

i have code:

ggplot() +    stat_smooth(data=fd.area.dfa.quant,aes(x=area,y=q50),alpha=0.6,colour="red")+   stat_smooth(data=fd.area.dfb.quant,aes(x=area,y=q50),alpha=0.6,colour="green")+   stat_smooth(data=fd.area.cfa.quant,aes(x=area,y=q50),alpha=0.6,colour="purple")+   stat_smooth(data=fd.area.csb.quant,aes(x=area,y=q50),alpha=0.6,colour="blue")+   stat_smooth(data=fd.area.bsk.quant,aes(x=area,y=q50),alpha=0.6,colour="orange")+   scale_x_log10("xlab",expand = c(0, 0),labels=comma)+   scale_y_log10("ylab", expand = c(0, 0.05),labels=comma)+   theme(aspect.ratio=1)+   ggtitle("title")+   ggsave("save2.png") 

this figureenter image description here

i

  1. add name each 5 lines (say: dfa,dfb,cfa,csb,bsk)
  2. after that, want display names in show_guide corresponding color.

p.s. lines of various sizes , hence avoiding melting.

how can it?

since didn't share sample data make code minimal, reproducible example, i'm going use own , may adapt it

d1<-data.frame(x=1:10, y=cumsum(runif(10))) d2<-data.frame(x=1:10, y=cumsum(runif(10)))  ggplot() +    stat_smooth(data=d1,aes(x,y,colour="mya"),alpha=0.6)+   stat_smooth(data=d2,aes(x,y,colour="myb"),alpha=0.6)+   scale_color_manual(name="line",values=c(mya="red",myb="green")) 

to work, set colour in aes() call , assign unique (non-color) name. then, manually add color scale , define color value each of aes-color values set. correctly create legend values.

enter image description here


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -