[R] Splitting device for ggplots?

baptiste auguie ba208 at exeter.ac.uk
Sat Nov 1 11:13:41 CET 2008


Hi,

I believe you can apply the same procedure as described in Paul  
Murrell's "R graphics" book for arranging lattice plots.


library(grid)
library(ggplot2)
?grid.layout

df <- data.frame(x=rnorm(100), y=rnorm(100))
df2 <- data.frame(x <- rnorm(100), y=runif(x))

p <- qplot(x,y, data=df)
p2 <- qplot(x,y, data=df2)

pushViewport(viewport(x=0.25, width = 0.5, height = 0.8, angle = 0,
name = "leftvp"))
grid.rect(gp = gpar(col = rgb(43/255, 140/255, 190/255)))
print(p, newpage=F)
upViewport()
pushViewport(viewport(x=0.75, width = 0.5, height = 0.8, angle = 0,
name = "rightvp"))
grid.rect(gp = gpar(col = rgb(43/255, 140/255, 190/255)))
print(p2, newpage=F)
upViewport()


Hope this helps,

baptiste

On 1 Nov 2008, at 09:35, Vitalie Spinu wrote:

> Dear UseRs,
>
> For various reasons I need to plot multiple ggplots on one device
> (preferably pdf). Is there a way to achieve that?
> par(mfrow), split.screen() and layout() seem not to do the job.
>
> Thanks,
> Vitalie.
>
> ______________________________________________
> 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.

_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag



More information about the R-help mailing list