本文介绍了如何使用堆叠的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
...

我想看看 M R 关于每个 F 值(1、2、3,...)。因此,我想在x轴上使用 F ,在y轴上使用 R ,并在 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 地图执行此类操作c $ c> panel.3dpolygon from 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 ,但我总是忘记下标 groups 可以按预期工作。

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