如何在一帧中绘制两个二元直方图?

时间:2019-07-11 14:32:00

标签: r 3d histogram overlap density-plot

我正在尝试在一个帧中绘制两个双变量直方图,以查看它们是否相等。我在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")

情节看起来像

enter image description here

因此,这些图以无法比较的方式重叠。我可以使其中任何一个图透明吗?预先感谢!

1 个答案:

答案 0 :(得分:2)

对于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) )

结果

enter image description here

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