Par (mfrow = c (1,2)), not displaying density charts side by side

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

enter image description here

However, when I try to make a tight side-by-side graph, the graphs are obtained separately:

 # 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 density plots?

+5
source share
1 answer

densityplot creates lattice plots (which are different from the base plots).

So, to have them nearby, 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

+8
source

All Articles