[R] Plotting a 3D surface from three variables

David Winsemius dwinsemius at comcast.net
Thu Apr 10 22:58:45 CEST 2014


On Apr 10, 2014, at 5:58 AM, Kumsa wrote:

> I'm trying to produce a 3d plot with wireframe function or any other
> package  in R . I want to show how z changes in response to x and y. But I
> fail to produce  a 3d surfaceplot with a  wireframe command  which gives me
> different  error messages.
> 
> ## Generate data
> x <- seq(from=0, to=100,by=1)
> y <- seq(from=0, to=20,by=1)
> df <- expand.grid(x=x,y=y)
> df$z<-1/(1+(exp(-(-1.42+0.04*df$x+0.4*df$y))))
> The command that I used is this one
> 
> require(lattice)
> wireframe(df ~ x * y, df, shade = TRUE, aspect = c(1, 1),light.source =
> c(10,10,10))
> 

Try changing the formula to : z ~ x + y

z ~ x * y also "works" but it looks wrong to my eyes.

-- 

David Winsemius
Alameda, CA, USA




More information about the R-help mailing list