从 x,y,z 数据框制作线框图 [英] Making a wireframe plot from an x,y,z data.frame

查看:26
本文介绍了从 x,y,z 数据框制作线框图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 x/y/z 点的 data.frame.我知道如何使用 rgl 包制作 3d 散点图,但我想连接散点图中的每个点以制作线框或曲面图.

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.

此代码返回散点图

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,type='wire')

我可以用格子制作我想要的情节:

I can make the plot I want with lattice:

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

我什至可以让它旋转:

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

但我更喜欢 rgl 而不是 lattice 因为它渲染得更快,并且可以让你用鼠标旋转图.

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

rgl 中制作线框图的正确方法是什么?

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

推荐答案

rgl 中的曲面绘图函数是 persp3d 和 base::persp 一样,它需要一个矩阵作为 z 参数的输入

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:

这篇关于从 x,y,z 数据框制作线框图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆