开发者

Making a wireframe plot from an x,y,z data.frame

开发者 https://www.devze.com 2023-04-05 02:34 出处:网络
I have a data.frame of x/y/z points.I know how to make a 3d scatterplot using the rgl package but I would like to connect each point in the scatterplot to make a wireframe or surface plot.

I have a data.frame of x/y/z points. I know how to make a 3d scatterplot using the rgl package but I would like to connect each point in the scatterplot to make a wireframe or surface plot.

This code returns the scatter plot

library(rgl)
Data <- expand.grid(x=seq(0,10),y=seq(0,10))
Data$z <- Data$x^2+Data$y^2
plot3d(Data)

While this code returns a blank graph:

plot3d(Data,typ开发者_如何学运维e='wire')

I can make the plot I want with lattice:

library(lattice)
wireframe(z~x+y,Data)

I can even make it rotate:

library(TeachingDemos)
rotate.wireframe(z~x+y,Data)

But I prefer rgl over lattice because it renders much quicker and lets you rotate the plot with the mouse.

Whats the proper way to make a wireframe plot in rgl?


The surface drawing plot function in rgl is persp3d and like base::persp, it needs a matrix as input to the z argument

zmat <- matrix(Data$z, 11,11)
persp3d(x=seq(0,10), y=seq(0,10), z=zmat)

I did spin this graphic a bit before capturing it with a screen grabbing program I use:

Making a wireframe plot from an x,y,z data.frame

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号