R 中的 3d 绘图 - 补丁
我的数据框中有以下数据:
**x** in (0,1)
**y** in [0,1]
**z** in [0,1]
例如:
X,Y,Z
0.1, 0.2, 0.56
0.1, 0.3, 0.57
...
我想将它们绘制在这种类型的图表上:
我在 R 上尝试过,但我所能得到的只是 不太花哨的 3d 散点图。 我还阅读了有关 晶格 3d 线框,但我无法理解它。
我应该怎么做才能在 R 中获得类似 Matlab 的线框? 涉及哪些数据转换?
这是文档中的示例代码:
x <- seq(-pi, pi, len = 20)
y <- seq(-pi, pi, len = 20)
g <- expand.grid(x = x, y = y)
g$z <- sin(sqrt(g$x^2 + g$y^2))
wireframe(z ~ x * y, g, drape = TRUE,
aspect = c(3,1), colorkey = TRUE)
我觉得它不是特别清楚。
编辑:persp3d
函数工作正常,我能够生成具有一种颜色的 3D 绘图。如何设置相对于 z 值的色标?
感谢您的任何提示, 穆隆
I have the following data in a data frame:
**x** in (0,1)
**y** in [0,1]
**z** in [0,1]
For example:
X,Y,Z
0.1, 0.2, 0.56
0.1, 0.3, 0.57
...
I'd like to plot them on this type of chart:
I tried on R, but all I could get was a not-so-fancy 3d scatterplot.
I also read about the lattice 3d wireframe, but I couldn't get my head around it.
What am I supposed to do to get a Matlab like wireframe in R?
What data transforms are involved?
This is the sample code from the documentation:
x <- seq(-pi, pi, len = 20)
y <- seq(-pi, pi, len = 20)
g <- expand.grid(x = x, y = y)
g$z <- sin(sqrt(g$x^2 + g$y^2))
wireframe(z ~ x * y, g, drape = TRUE,
aspect = c(3,1), colorkey = TRUE)
I don't find it particularly clear.
EDIT: the persp3d
function works fine, and I was able to generate a 3d plot with one colour. How can I set a colour scale relative to the z value?
Thanks for any hints,
Mulone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
outer
创建 z 值,然后使用persp
绘制:有用于着色和设置视角的选项,请参阅
?persp
。请参阅 Matlab 风格着色的第四个示例。对于交互式绘图,请考虑使用
rgl
包中的persp3d
:编辑
要添加颜色,与
中的方法略有不同>persp
,因为颜色与顶点相关而不是与面的中心相关,但它使事情变得更容易。帮助文件建议添加参数
smooth=FALSE
,但这取决于个人喜好。Use
outer
to create the z values and then usepersp
to plot:There are options for colouring and setting the viewing angle, see
?persp
. See the fourth example for Matlab style colouring.For an interactive plot, consider using
persp3d
in thergl
package:Edit
To add colour, there is a slight difference from the method in
persp
, since the colour relates to the vertex rather than the centre of the facet, but it makes it easier.The help file recommends adding the parameter
smooth=FALSE
, but that's down to personal preference.