Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding points to 3d plot in r

Tags:

r

graphics

3d

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))?

like image 579
jjankowiak Avatar asked Dec 28 '14 23:12

jjankowiak


1 Answers

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
like image 148
Ben Bolker Avatar answered Oct 24 '22 06:10

Ben Bolker