在r中添加点到3d图 [英] Adding points to 3d plot in r

查看:199
本文介绍了在r中添加点到3d图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是初学者,在3D中绘制R,我需要帮助。我尝试绘制一些简单的抛物线b

$ p $ lt; code> library(rgl)
x< - seq(-1,1,0.2 )
y< - x
f< - 函数(x,y){
- (x ^ 2 + y ^ 2)
}
z< - 外层(x,y,f)
persp3d(x,y,z,col =gray)

所以,我的问题是:


  1. 我可以只绘制网格,还可以让颜色透明在后面的部分?


  2. 如何给曲线添加点(在曲面上,例如绘制其他色点(1,1 ,2))?



解决方案

material3d 获取表面属性的信息。大多数这些属性,如 alpha front =line back =行,可以直接传递给 persp3d()。用 points3d()(或 spheres3d())添加点。

  persp3d(x,y,z,col =gray,alpha = 0.5)
points3d(1,1,2,col =red)
persp3d(x,y,z,col =gray,front =line,back =line)
spheres3d(1,1,2,col =red,radius = 5 )##适当的半径:我用x <-y < - 1:20


I'm beginner with plotting in 3D in R and I need help. I try to plot some easy paraboloid

library(rgl)
x <- seq(-1,1, 0.2)
y <- x
f <- function(x,y){
   -(x^2+y^2)
}
z <- outer(x,y, "f")
persp3d(x, y, z, col="gray")

So, my questions are:

  1. Can I draw only grid, or make color transparent to see also the part of "at the back"?

  2. How to add points to the plot (on the surface, e.g to draw in other color point (1,1,2))?

解决方案

See ?material3d for information on surface properties. Most of these properties, such as alpha or front="line" or back="line", can be passed directly to persp3d(). Add points with points3d() (or spheres3d()).

persp3d(x, y, z, col="gray", alpha=0.5)
points3d(1,1,2,col="red")
persp3d(x, y, z, col="gray", front="line", back="line")
spheres3d(1,1,2,col="red",radius=5)  ## appropriate radius: I used x <- y <- 1:20

这篇关于在r中添加点到3d图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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