Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

par(mfrow=c(1,2)) not displaying side-by-side densityplots [duplicate]

Tags:

r

par(mfrow=c(1,2))
plot(1:12, log = "y")
plot(1:2, xaxs = "i")

enter image description here

However, when I try to do a side-by-side densityplot the plots get output seperately:

# load the stud.recs dataset
library(UsingR)

par(mfrow=c(1,2))
densityplot(stud.recs$sat.v)
densityplot(stud.recs$sat.m)

Why is par(mfrow=c(1,2)) not working for the density plots?

like image 262
Chris Snow Avatar asked Jun 28 '15 11:06

Chris Snow


1 Answers

densityplot produces lattice plots (which are different to base plots).

So in order to have them side by side you need to do:

library(UsingR)
par(mfrow=c(1,2))
a <- densityplot(stud.recs$sat.v)
b <- densityplot(stud.recs$sat.m)

#this is the print.lattice method below
# ?print.trellis for help
print(a, position = c(0, 0, 0.5, 1), more = TRUE)
print(b, position = c(0.5, 0, 1, 1))

enter image description here

like image 60
LyzandeR Avatar answered Oct 26 '22 06:10

LyzandeR