[R] ggplot2: legend
petr.pikal at precheza.cz
Wed Jul 4 09:29:09 CEST 2012
I do not have direct answer. You shall probably search ggplot2 web.
Searching "legend" gave me about sixty results from which you probably
could learn how to modify legend(s) according to your wish.
> Dear all,
> I produced the following graph with ggplot which is almost fine, yet I
> don't like that the legend for "Means" and "Observations" includes a
> though no line is used in the plot for those two (the line for "Overall
> Mean" on the other hand is wanted):
> ddf <- data.frame(x = factor(rep(LETTERS[1:2], 5)), y = rnorm(10))
> p <- ggplot(ddf, aes(x = x, y = y))
> p + geom_point(aes(colour="Observations", shape="Observations")) +
> stat_summary(aes(colour = "Means", shape ="Means"),
> fun.y = mean, fun.ymin = min, fun.ymax = max,
> geom = "point") +
> geom_hline(aes(yintercept = mean(y), linetype = "Overall Mean"),
> show_guide = TRUE)
> I tried to map the linetype in geom_point (and stat_summary) to NULL and
> tried to set it to "blank" but neither worked.
> Is it furthermore possible to combine the two legends? My preferred plot
> would have two symbols with different colours and shapes for "Means" and
> "Observations" (but no line) and directly below that a line for "Overall
> Mean" (that is all the three items in one legend)? For that I tried to
> assign the same names to the legends but this did not work either.
> So any help would be highly appreciated.
> Kind Regards,
> Thorn Thaler
> Applied Mathematics
> Nestec Ltd,
> Nestlé Research Center
> PO Box 44
> CH-1000 Lausanne 26
> Phone: +41 21 785 8220
> Fax: +41 21 785 9486
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help