Megan Bartlett
2011-Oct-24 17:23 UTC
[R] Adding points to a wireframe: 'x and units must have length >0' error
Hi, I'm trying to follow the suggestions given by Deepayan Sarkar in this message: http://tolstoy.newcastle.edu.au/R/help/05/11/16135.html to plot 3-D points on a wireframe plot. The problem is that I keep getting a partly formed plot- with the colored lattice visible but no axis labels or additional points- with the error message "error using packet 1, 'x' and 'units' must have length >0". Does anyone know what I'm doing wrong? The code I've been using is: # generate some fake data data.frame(x = seq(-4, 0, 0.5), y = seq(0, 40, 5))-> df expand.grid(x = df$x, y = df$y) -> gridd (gridd$y* gridd$x) -> gridd$z data.frame(x = runif(10, -4, 0), y = runif(10, 0, 40))-> pts1 pts1$z <- pts1$x*pts1$y # plot wireframe(z ~ y*x, gridd, drape = TRUE, colorkey= TRUE, scales = list(arrows = FALSE), pts = pts1, panel.3d.wireframe function(x, y, z,xlim, ylim, zlim, xlim.scaled, ylim.scaled, zlim.scaled, pts1, ...) { panel.3dwire(x = x, y = y, z = z, xlim = c(-4, 0), ylim = c(0, 40), zlim = c(-160, 0), xlim.scaled = c(-0.5, 0.5), ylim.scaled = c(-0.5, 0.5), zlim.scaled = c(-0.5, 0.5), ...) xx <- xlim.scaled[1] + diff(xlim.scaled) * (pts1$x - xlim[1]) / diff(xlim) yy <- ylim.scaled[1] + diff(ylim.scaled) * (pts1$y - ylim[1]) / diff(ylim) zz <- zlim.scaled[1] + diff(zlim.scaled) * (pts1$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, ...) }) Thanks so much! -Megan Bartlett [[alternative HTML version deleted]]
David Winsemius
2011-Oct-24 19:04 UTC
[R] Adding points to a wireframe: 'x and units must have length >0' error
On Oct 24, 2011, at 1:23 PM, Megan Bartlett wrote:> Hi, > > I'm trying to follow the suggestions given by Deepayan Sarkar in this > message: > > http://tolstoy.newcastle.edu.au/R/help/05/11/16135.html > > to plot 3-D points on a wireframe plot. The problem is that I keep > getting a > partly formed plot- with the colored lattice visible but no axis > labels or > additional points- with the error message "error using packet 1, 'x' > and > 'units' must have length >0". Does anyone know what I'm doing > wrong? The > code I've been using is: > > # generate some fake data > data.frame(x = seq(-4, 0, 0.5), y = seq(0, 40, 5))-> df > expand.grid(x = df$x, y = df$y) -> gridd > (gridd$y* gridd$x) -> gridd$z > > data.frame(x = runif(10, -4, 0), y = runif(10, 0, 40))-> pts1 > pts1$z <- pts1$x*pts1$y > > # plot > > wireframe(z ~ y*x, gridd, drape = TRUE, colorkey= TRUE, > scales = list(arrows = FALSE), > pts = pts1, > panel.3d.wireframe > function(x, y, z,xlim, ylim, zlim, xlim.scaled, ylim.scaled, > zlim.scaled, pts1, ...) > > { > panel.3dwire(x = x, y = y, z = z, > xlim = c(-4, 0), > ylim = c(0, 40), > zlim = c(-160, 0), > xlim.scaled = c(-0.5, 0.5), > ylim.scaled = c(-0.5, 0.5), > zlim.scaled = c(-0.5, 0.5), > ...) > xx <- xlim.scaled[1] + diff(xlim.scaled) * (pts1$x - xlim[1]) / > diff(xlim) > yy <- ylim.scaled[1] + diff(ylim.scaled) * (pts1$y - ylim[1]) / > diff(ylim) > zz <- zlim.scaled[1] + diff(zlim.scaled) * (pts1$z - zlim[1]) / > diff(zlim) > panel.3dscatter(x = xx,You assigned 'pts1' to 'pts', so you should have used 'pts' above:> y = yy, > z = zz, > xlim = xlim, > ylim = ylim, > zlim = zlim, > xlim.scaled = xlim.scaled, > ylim.scaled = ylim.scaled, > zlim.scaled = zlim.scaled, > ...) > }) > > Thanks so much! > > -Megan Bartlett > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT