[R] How to add/draw a persp3d graph to a plot with an existing surface/graph
Duncan Murdoch
murdoch.duncan at gmail.com
Tue Mar 13 11:04:10 CET 2012
On 12-03-12 5:45 PM, Michael wrote:
> Dear R users,
>
> I have been trying to draw the following 3d graphs: The solid region bounded
> above by the paraboloid z = 9 - x2 - y2 and below by the unit circle in the
> xy-plane.
>
> I wanted to visualize the solid region bounded by those two graphs. I could
> draw those two 3d graphs separately, but I could not get those two to work
> in one single plot.
>
> Here's my code for the paraboloid:
> x<- seq(-10, 10, length= 30)
> y<- x
> f<- function(x,y) { 9-x^2-y^2 }
> z<- outer(x, y, f)
> persp3d(x, y, z, aspect=c(1, 1, 1), col = "lightblue",
> xlab = "X", ylab = "Y", zlab = "9-x^2-y^2")
>
> And my code for the cylinder with the unit circle as the base:
>
> z<- matrix(seq(0, 1, len=50), 50, 50)
> theta<- t(z)
> x<- cos(theta*2*pi)
> y<- sin(theta*2*pi)
> persp3d(x, y, z, col="red",add=T)
>
> I wonder if the other R users have encountered similar problems. If someone
> can help me out, I'll be very appreciative.
>
I think the graph is working, it's just that the cylinder is really tiny
and hard to see. Your z range goes from -190 to 9 in the first graph,
but from 0 to 1 in the cylinder. Try using -200*z + 9 in the second
plot, and you'll see the cylinder clearly.
Duncan Murdoch
More information about the R-help
mailing list