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

Chr*_*now 6 r

par(mfrow=c(1,2))
plot(1:12, log = "y")
plot(1:2, xaxs = "i")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

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

# load the stud.recs dataset
library(UsingR)

par(mfrow=c(1,2))
densityplot(stud.recs$sat.v)
densityplot(stud.recs$sat.m)
Run Code Online (Sandbox Code Playgroud)

为什么par(mfrow=c(1,2))不为密度图工作?

Lyz*_*deR 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))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 这个建议的解决方案对我不起作用。 (5认同)