par(mfrow=c(1,2))
plot(1:12, log = "y")
plot(1:2, xaxs = "i")
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?
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With