[R] ggplot: Problem with legend background

hadley wickham h.wickham at gmail.com
Fri Dec 11 19:14:03 CET 2009


Hi Luc,

You want:

legend.title=theme_text(size=20, hjust = 0)

So the legend title is left aligned, not centred.

Hadley


On Fri, Dec 11, 2009 at 9:26 AM, MUHC_Research
<villandl at dms.umontreal.ca> wrote:
>
> Dear R-users,
>
> I am preparing graphs for an upcoming article using the different functions
> of the ggplot2 package and I've been having problems with the legend
> background. It doesn't seem to scale when the text size is increased. Here's
> the mandatory reproducible example:
>
> library(ggplot2)
> repFrame <- data.frame(A= 1:10, B= rnorm(1:10), groupNum = rep(c("First
> group", "Second group"),each=5))
> testPlot <- ggplot(repFrame, aes(x=A, y = B, group = groupNum)) +
> opts(legend.position=c(0.85,0.3), legend.background =
> theme_rect(fill="white"), legend.text=theme_text(size=16),
> legend.title=theme_text(size=20))
> testPlot + geom_point(aes(colour= groupNum))
>
> As you can see, the text doesn't fit in the white rectangle. I suspect there
> is a theme setting I could modify to fix this, but I can't seem to find
> which one.
>
> I sincerely thank you for your time and assistance.
>
> Luc
> --
> View this message in context: http://n4.nabble.com/ggplot-Problem-with-legend-background-tp961142p961142.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
http://had.co.nz/




More information about the R-help mailing list