本文介绍了如何使用堆叠的 2d 图制作 3d 图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制如下.我试图搜索几个包和绘图函数,但找不到解决方案.

I want to plot as below. I tried to search several packages and plot functions but I couldn't find a solution.

我的数据有四列.

ID  F  R  M
 1  2  3  4
 2  4  6  7
...

我想看看 MR 之间关于每个 F 值(1, 2, 3, ...).所以,我希望 F 沿 x 轴,R 沿 y 轴,M 作为 z 轴,如下图.

I want to see the relationship between M and R with respect to each F value (1, 2, 3, ...). So, I'd like F along the x-axis, R along the y-axis, and M as the z-axis as in the below graph.

谢谢.

推荐答案

你可以用 lattice cloud 绘图来做这种事情,使用 panel.3dpolygon 来自 latticeExtra.

You can do this kind of thing with lattice cloud plots, using panel.3dpolygon from latticeExtra.

library(latticeExtra)

# generating random data
d <- data.frame(x=rep(1:40, 7), y=rep(1:7, each=40),
                z=c(sapply(1:7, function(x) runif(40, 10*x, 10*x+20))))

# define the panel function
f <- function(x, y, z, groups, subscripts, ...) {
  colorz <- c('#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3',
              '#fdb462', '#b3de69')
  sapply(sort(unique(groups), decreasing=TRUE), function(i) {
    zz <- z[subscripts][groups==i]
    yy <- y[subscripts][groups==i]
    xx <- x[subscripts][groups==i]
    panel.3dpolygon(c(xx, rev(xx)), c(yy, yy),
                    c(zz, rep(-0.5, length(zz))),
                    col=colorz[i], ...)
  })

}

# plot
cloud(z~x+y, d, groups=y, panel.3d.cloud=f, scales=list(arrows=FALSE))

我确定我不需要在面板函数中循环groups,但我总是忘记subscriptsgroups 按预期工作.

I'm sure I don't need to loop over groups in the panel function, but I always forget the correct incantation for subscripts and groups to work as intended.

正如其他人在评论中提到的,这种类型的情节可能看起来很时髦,但可能会掩盖数据.

As others have mentioned in comments, this type of plot might look snazzy, but can obscure data.

这篇关于如何使用堆叠的 2d 图制作 3d 图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 07:13