[R] ggplot2: how to increase size of legend box when converting to pdf

Ranjan Maitra maitra.mbox.ignored at inbox.com
Mon Mar 3 22:02:21 CET 2014


Hi,

I have struggled with this quite a bit (all morning and afternoon) and I
am not sure I am any close to a solution. Basically, here is my sample
code:

require(grid)
require(ggplot2)

X <- data.frame(x = c(rnorm(10), rnorm(10, mean = 2, sd = 2), rnorm(10,
mean =5)), group = c(rep("Ellipse", 10), rep("PeakAmp", 10), rep
("Rectangle", 10)))



bp <- ggplot(data=X, aes(x=group, y=x, colour=group)) + geom_point() +
theme_bw()

bp +  theme(legend.background = element_rect(fill = "white", color =
"black",                 size = 0.1, linetype="solid"), legend.key =
element_rect(fill = 'white', color = "white", size = 0.1),
              legend.text = element_text(size = 8),
              legend.key.height = unit(0.5, "cm"),
              legend.key.width = unit(0.5, "cm"),
              legend.justification=c(0.9,0.1), legend.position=c(0.9,
0.1))

dev.copy2pdf(file = "Rplots.pdf", height = 4, width = 6.5)


I get exactly what i want on the plotting device (x11). However, the
pdf has text spilling out of the legend box. I understand that this
could  be an issue of the viewer and the encoding but is there anything
I can do in R to reliably get around this issue in the plots
preparation stage?

Many thanks and best wishes,
Ranjan

____________________________________________________________
Protect your computer files with professional cloud backup.
Get PCRx Backup and upload unlimited files automatically. 
Learn more at http://backup.pcrx.com/mail



More information about the R-help mailing list