Hi, I got the same result with David's version, but defining the *lim values prior to the function actually made it work. I also renamed the points pts so it wouldn't matter whether it was pts1 or pts. The new code is:
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))-> pts pts$z <- pts$x*pts$y wireframe(z ~ x*y, gridd, drape = TRUE, colorkey= TRUE, scales = list(arrows = FALSE), xlim = c(-4, 0), ylim = c(0, 40), zlim = c(-160, 0), 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.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) * (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, ...) }) Thanks so much!! -Megan On Mon, Oct 24, 2011 at 2:25 PM, Dennis Murphy <djmu...@gmail.com> wrote: > Hi David: > > When I try your code, I get the wireframe with the x, y, z axes sans > bounding cube and points, along with the error message > > Error using packet 1 > object 'pts' not found > > > sessionInfo() > R version 2.13.1 (2011-07-08) > Platform: x86_64-pc-mingw32/x64 (64-bit) > > locale: > [1] LC_COLLATE=English_United States.1252 > [2] LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 > [4] LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] sos_1.3-1 brew_1.0-6 lattice_0.19-33 > > loaded via a namespace (and not attached): > [1] grid_2.13.1 tools_2.13.1 > > Dennis > > On Mon, Oct 24, 2011 at 1:45 PM, David Winsemius <dwinsem...@comcast.net> > wrote: > > > > On Oct 24, 2011, at 4:12 PM, Megan Bartlett wrote: > > > >> Hi David, > >> > >> Thanks for the suggestion - I changed pts1 to pts, but I still got > >> the same error as before. Do you know what else I'm doing wrong? > > > > I do not. The code that works for me is: > > > > 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) * (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, > > ...) > > }) > > > > -- > > David. > >> > >> Thanks, > >> > >> Megan > >> > >> PS. New code is: > >> > >> 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, pts, ...) > >> > >> { > >> 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) * (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, > >> ...) > >> }) > >> > >> > >> On Mon, Oct 24, 2011 at 12:04 PM, David Winsemius < > dwinsem...@comcast.net > >> > wrote: > >> > >> 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@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 > >> > >> > > > > David Winsemius, MD > > West Hartford, CT > > > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@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. > > > [[alternative HTML version deleted]] ______________________________________________ R-help@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.