[R] wireframe - add data points

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Apr 30 18:01:06 CEST 2008


On 4/30/08, Strubbe Diederik <diederik.strubbe at ua.ac.be> wrote:
> Hello all,
>
>  I'm trying to add some data points to a wireframe. X an Y axis are independent variables, Z axis is predicted probability. I'd like to add the original data points on which the predicted probabilities are based to the wireframe. I've followed some of the previous post on this but get stuck :
>
>  ## first part yields the wireframe##
>  setwd("C:/Temp")
>   rnp <- read.table("interact.csv",header=T,sep=";")
>   status <-rnp[,1:1]
>   totalfrost <- rnp[,2:2]
>   logtps <- rnp[,3:3]
>   logpd <- rnp[,4:4]
>   logwinterp <- rnp[,5:5]
>  model <- glm(status~totalfrost+logtps+logpd+logwinterp+totalfrost*logtps+totalfrost*logwinterp,binomial)
>  abc <- expand.grid(totalfrost=seq(-1.9,3.6,by=0.25),logtps=seq(-3.3,1.1,by=0.25),logpd=seq(0.95,4.1, by=0.25),logwinterp=seq(1.49,1.78, by=0.25))
>  abc$status <-as.vector(predict(model,abc,type="response"))
>
>  ##below is the import of the original data together with their predicted probabilities##
>  punten <- read.table("probs.csv",header=T,sep=";")
>  x <- punten[,1:1]
>  y <- punten[,2:2]
>  z <- punten[,3:3]
>
>  pts <- data.frame(x=x,y=y,z=z)
>  ##end import original data##
>
>
>  wireframe(status~totalfrost*logtps,abc,scales=list(arrows=TRUE),drape=TRUE, screen =list (x=15, y=-50, z=-105), pts = pts,
>  panel.3d.wireframe =
>           function(x, y, z,
>                    xlim, ylim, zlim,
>                    xlim.scaled, ylim.scaled, zlim.scaled,
>                    pts,
>                    ...) {
>               panel.3dwire(x = x, y = y, z = z,
>                            xlim = xlim,
>                            ylim = ylim,
>                            zlim = zlim,
>                            xlim.scaled = xlim.scaled,
>                            ylim.scaled = ylim.scaled,
>                            zlim.scaled = zlim.scaled,
>                            ...)
>               xx <-
>                   xlim.scaled[1] + diff(xlim.scaled) *
>                       (pts$x - xlim[1]) / diff(xlim)
>               yy <-
>                   ylim.scaled[1] + diff(ylim.scaled) *
>                       (pts$y - ylim[1]) / diff(ylim)
>               zz <-
>                   zlim.scaled[1] + diff(zlim.scaled) *
>                       (pts$z - zlim[1]) / diff(zlim)
>               panel.3dscatter(x = xx,
>                               y = yy,
>                               z = zz,
>                               xlim = xlim,
>                               ylim = ylim,
>                               zlim = zlim,
>                               xlim.scaled = xlim.scaled,
>                               ylim.scaled = ylim.scaled,
>                               zlim.scaled = zlim.scaled,
>                               ...)
>           })
>
>  This yields me the following errors :
>
>  Warning messages:
>  1: In Ops.factor(pts$x, xlim[1]) : - not meaningful for factors
>  2: In Ops.factor(pts$y, ylim[1]) : - not meaningful for factors
>  3: In Ops.factor(pts$z, zlim[1]) : - not meaningful for factors
>
>  Any idea about what is wrong and what to do about it?

Without access to the data, my only guess is that pty$x etc. are
factors. Can you show us tthe output of str(pts)?

-Deepayan



More information about the R-help mailing list