r - Colour of geom_hline is not correct in legend [ggplot2] -


i've looked around on can't seem find solution. i've used geom_point , geom_hline in ggplot2 , have gotten satisfactory legends both. however, have 1 black line , 1 blue line in figure in legend both black - how can correct in legend right colors?

mcgc <- ggplot(sam, aes(x = person,y = mm, colour = x)) +                   geom_point(size = 0.75) +                   scale_colour_gradient2(high="red", mid="green", limits=c(0,1), guide = "colourbar") +                   geom_hline(aes(yintercept = mad, linetype = "mad"), colour = "blue", size=0.75, show_guide = true) +                   geom_hline(aes(yintercept = mmad, linetype = "mmad"), colour = "black", size=0.75, show_guide = true)  +                   facet_wrap(~ plan, scales = "free", ncol = 4) +                   scale_linetype_manual(name = "plan of health care", values = c("mad" = 1, "mmad" = 1),guide = "legend") 

i'm sure i've on written here... not sure (am new ggplot)

data:

plan  person x       mm  mad mmad 1  1 95 0.323000 0.400303 0.12 1  2 275 0.341818 0.400303 0.12 1  3  2 0.618000 0.400303 0.12 1  4 75 0.320000 0.400303 0.12 1  5 13 0.399000 0.400303 0.12 1  6 20 0.400000 0.400303 0.12 2  1 219 0.393000 0.353350 0.45 2  2 50 0.060000 0.353350 0.45 2  3 213 0.390000 0.353350 0.45 2  4 204 0.496100 0.353350 0.45 2  5 19 0.393000 0.353350 0.45 2  6 201 0.388000 0.353350 0.45 

plan goes 40, i've included snippet of data here...

update: might helping out - code plot data wrong. i've updated this.

as using colors points can't use scale_color_.. line show colors in legend. workaround use function guides() argument override.aes= add colors legend. add line existing code.

  + guides(linetype=guide_legend(override.aes=list(colour = c("blue","black")))) 

enter image description here


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -