[R] combining multiple 3D graphs
Duncan Murdoch
murdoch at stats.uwo.ca
Wed Oct 21 16:34:03 CEST 2009
On 10/21/2009 9:03 AM, Michael Ralph M. Abrigo wrote:
> Hi all!
> I am a grad stat student and is fairly new in using R. I am doing a
> regression tree in one of my problem sets. I have already identified the
> cut-points (using Stata) for the regression. My problem is how to graph the
> fitted values of z against the independent variables x and y. Basically, I
> want to graph the following:
> z=87.67 if 0<x<=29 & 0<y<=48
> z=75 if 0<x<=29 & 48<y<=62
> z=67 if 29<x<=36 & 0<y<=62
> z=56.71 if 36<x<=45 & 0<y<=62
> z=40.8 if 36<x<=55 & 0<y<=62
> I have some idea (still to be implemented) on how to graph them piece-wise
> using "persp". My question is this:how do one combine multiple 3D graphs
> (using "persp") in R? better yet, is there a way to graph them all in just
> one go?
I would define a function of x and y which evaluates to your fitted
values, evaluate it on a grid, and then use persp. You might already
have code to do this, or you might have to write it something like this:
f <- function(x,y) {
ifelse( 0 < x & x <= 29 & 0 < y & y <= 48, 87.67,
ifelse( 0 < x & x <= 29 & y < 48 & y <= 62, 75,
}
etc. I leave the difficult problem of properly closing all the
parentheses to you!
Duncan Murdoch
More information about the R-help
mailing list