Two different ways:
library(ggplot2)
x=5
size=50
A=data.frame(X=sample(x, size, replace=T), Y=sample(x, size, replace=T),a=rep(1:2,each=25));A
# Facetting
qplot(X,Y,data=A) + geom_jitter(position=position_jitter(width=.03)) + facet_grid(.~a)
# Or with vp
p=qplot(X, Y, data=A) + geom_jitter(position=position_jitter(width=.03))
ggsave(p, file='main.png')
p1=qplot(X, Y, data=A) + geom_jitter(position=position_jitter(width=.3))
ggsave(p1, file='main2.png')
vport <- function(x, y)
viewport(layout.pos.row=x, layout.pos.col=y)
grid.newpage()
pushViewport(viewport(layout=grid.layout(1,2)))
print(p, vp=vport(1,1))
print(p1, vp=vport(1,2))
?
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
----- Original Message ----
From: Erik Iverson <eriki at ccbr.umn.edu>
To: Peng Yu <pengyu.ut at gmail.com>
Cc: ggplot2 <ggplot2 at googlegroups.com>
Sent: Sun, May 30, 2010 7:45:22 PM
Subject: Re: Put two plots side by side
I want to put the above two plots side by side (essentially,
to mimic
par(mfrow=c(1,2)) in the traditional graphic system). Is there
a
convenient way to do so in ggplot2?
Yes.
My
understanding is that you need to create use grid functions to do this. You can
create a viewport with a layout (using grid.layout) and then print the ggplot2
objects using the vp argument.? I don't know if there is a ggplot2
abstraction for this idea.