简体   繁体   English

使用 plot3D 或 plotly 在 R 中绘制 3D 曲面图

[英]3D surface plot in R with plot3D or plotly

I want to produce a 3D surface in R where y is flux, x is Age and z is precipitation.我想在 R 中生成一个 3D 表面,其中 y 是通量, x是年龄, z是降水。 I have a range of age between 0 and 152 and a range of precipitation 0 and 2600.我的年龄范围在 0 到 152 之间,降水范围在 0 到 2600 之间。

I also have two functions where flux is function of Age or Precipitation:我还有两个函数,其中通量是年龄或降水的函数:

Flux= 0.387217066*(Age^0.328086337)*(exp(-0.004177033*Age)

and

Flux= 1.117997*(1-exp(-exp(-5.426564)*(Preci-(-220.745499))

What I want to achieve is something a bit like this :我想要实现的有点像这样

在此处输入图片说明

I have tried to do it with the package plot3D in R without success (see below)我试图用 R 中的包plot3D来做但没有成功(见下文)

Age<- as.matrix(seq(0:152)) 
Preci<-as.matrix(seq(from=10, to=2600, by=17))
Flux= as.matrix(0.387217066*(Age^0.328086337)*(exp(-0.004177033*Age)) - 1.117997*(1-exp(-exp(-5.426564)*(Preci-(-220.745499)))))
surf3D(Age, Preci, Flux, colvar = Flux, colkey = FALSE, facets = FALSE)

I got this error message我收到此错误消息

Error in if (is.na(var)) ispresent <- FALSE else if (length(var) == 1) if (is.logical(var)) if (!var) ispresent <- FALSE : 
  argument is of length zero

Here's a start, using emdbook::curve3d() as a wrapper for lattice::wireframe (see the sys3d argument to ?curve3d ).这是一个开始,使用emdbook::curve3d()作为lattice::wireframe的包装器(参见?curve3dsys3d参数)。 It's not obvious to me why it would make sense to combine your functions of flux as a function of age vs precip by subtracting one from the other, but as that's what you did above ...我不清楚为什么通过从另一个中减去一个来将你的通量函数作为年龄与降水的函数结合起来是有意义的,但正如你在上面所做的那样......

## for readability, put numeric values in a separate vector
params <- c(a0=0.387217066,a1=0.328086337,a2=0.004177033,
            p0=1.117997,p1=5.426564,p2=-220.745499)

library("emdbook")

curve3d(with(as.list(params),
          a0*(Age^a1)*exp(-a2*Age)-
            p0*(1-exp(-exp(-p1)*(Preci-p2)))),
        varnames=c("Age","Preci"),
        xlim=c(0,200),ylim=c(10,2600),
        sys3d="wireframe",
        col="gray",
        zlab="Flux")

在此处输入图片说明

curve3d also returns a list with components $x , $y , $z that you can use as input to other 3D graphing frameworks. curve3d还返回一个包含$x$y$z组件的列表,您可以将其用作其他 3D 图形框架的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM