par(mfrow = c(1,2))不显示并排密度图

时间:2015-06-28 11:28:10

标签: r

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

enter image description here

然而,当我尝试并排密度图时,这些图分别得到输出:

# load the stud.recs dataset
library(UsingR)

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

为什么par(mfrow=c(1,2))不能用于密度图?

1 个答案:

答案 0 :(得分:7)

densityplot产生晶格图(与基图不同)。

因此,为了让它们并排,您需要这样做:

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