如何在单个帧中绘制两个双变量直方图?

How to plot two bivariate histograms in a single frame?

我正在尝试在单个帧中绘制两个双变量直方图以查看它们是否相等。我在下面放了一个带有随机生成数据的 MWE。

x1 = seq(1, 5, length.out = 20)
x2 = seq(1, 5, length.out = 20)
x3 = matrix(rnorm(400), 20, 20)

y1 = seq(1, 5, length.out = 20)
y2 = seq(1, 5, length.out = 20)
y3 = matrix(rcauchy(400), 20, 20)

persp(x1, x2, x3, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
par(new = TRUE)
persp(y1, y2, y3, theta = 30, phi = 30, expand = 0.5, col = "green")

剧情好像

因此,这些地块以我无法比较的方式重叠。我可以让任何一个情节以某种方式透明吗?提前致谢!

您可以将 rgb() 与选项 alpha 一起用于 col

persp(x1, x2, x3, theta=30, phi=30, expand=0.5, col=rgb(0,0,1,alpha=0.3) )
par(new=TRUE)
persp(y1, y2, y3, theta=30, phi=30, expand=0.5, col=rgb(0,1,0,alpha=0.3) )

结果

注意: 为避免标签重叠,请添加 xlab="", ylab="", zlab="" 选项,例如到第二个情节。