[R] Colour of geom_hline is not correct in legend

Kate Ignatius kate.ignatius at gmail.com
Sun Apr 6 21:29:04 CEST 2014


I've used geom_point and geom_hline in ggplot2 and have gotten
satisfactory legends for both.  However, I have one black line and one
blue line in the figure but in the legend they are both black - how
can I correct this in the legend to be the right colors?

    mcgc <- ggplot(sam, aes(x = m,y = ad, 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 over written something here... just not sure where (am
new to ggplot)

Data:

    Plan  ad X       m  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 up to 40, but I've only included a snippet of data here...




More information about the R-help mailing list