[R] Adding points to a wireframe: 'x and units must have length >0' error

David Winsemius dwinsemius at comcast.net
Tue Oct 25 00:05:23 CEST 2011


On Oct 24, 2011, at 5:25 PM, Dennis Murphy 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

Hi Dennis;

My code was run with 2 objects, one named 'pts1' and the other 'pts'  
in the global environment as defined by one of Megan's posts. I don't  
remember why I constructed pts in the .GlobalEnv.

  dput(pts1)
structure(list(x = c(-0.0419496586546302, -1.39076532330364,
-1.53872193582356, -0.839783592149615, -1.88289892859757,  
-2.52944178972393,
-1.23924672044814, -2.46829973813146, -1.2426444850862,  
-3.86455787997693
), y = c(31.9964704941958, 31.6723003052175, 31.2804223783314,
17.4949281662703, 22.1439493726939, 14.630113914609, 35.1232215203345,
32.1026838570833, 12.7179794665426, 6.87488709576428), z =  
c(-1.34224101538446,
-44.0487369737558, -48.1318720753647, -14.6919536198699,  
-41.6948185487642,
-37.0060215240335, -43.5263370806479, -79.2390461577559,  
-15.8039270455387,
-26.5683990998875)), .Names = c("x", "y", "z"), row.names = c(NA,
-10L), class = "data.frame")

 > dput(pts)
structure(list(x = c(-0.709913841938187, -2.226621954599,  
-1.02527262434301,
0.147471310497732, 2.89475540039884, -1.68228706472879,  
1.73863850383242,
1.59522310445109, 3.04188037381882, -2.36433846151287), y =  
c(-2.94305674070926,
0.554983744134881, -0.176610316985743, 2.69128450161348,  
-0.14117131376901,
-0.956096979105434, -1.43965903354312, 2.39438632633848,  
1.96241983601171,
1.39501741394904), z = c(-0.0230211657471955, 0.734076026827097,
-0.206860289443284, -0.302051985170692, -0.498272170778364,  
0.295380563940853,
-0.0442760540172458, 0.771657421719283, -0.60832396754995,  
0.945741532370448
)), .Names = c("x", "y", "z"), row.names = c(NA, -10L), class =  
"data.frame")

With reference to Megan's report of success after "defining the *lim  
values prior to the function actually made it work" , I checked to see  
if I had perhaps done something like that and did not find anything:

 > grep("lim", ls())
integer(0)


I suppose there are other possible differences because I have quite a  
few more packages loaded:

 > sessionInfo()
R version 2.13.1 RC (2011-07-03 r56263)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
  [1] tcltk     grid      splines   stats     graphics  grDevices utils
  [8] datasets  methods   base

other attached packages:
  [1] zoo_1.7-4             RJDBC_0.2-0           rJava_0.9-1
  [4] sqldf_0.3-5           chron_2.3-39          gsubfn_0.5-5
  [7] RSQLite.extfuns_0.0.1 RSQLite_0.9-4         DBI_0.2-5
[10] mnormt_1.4-3          geepack_1.0-18        doBy_4.4.0
[13] MASS_7.3-13           snow_0.3-5            lme4_0.999375-39
[16] Matrix_0.999375-50    multcomp_1.2-7        mvtnorm_0.9-999
[19] R2HTML_2.2            ggplot2_0.8.9         proto_0.3-9.2
[22] reshape_0.8.4         plyr_1.6              reshape2_1.1
[25] akima_0.5-4           foreign_0.8-45        rms_3.3-1
[28] Hmisc_3.8-3           survival_2.36-9       sos_1.3-1
[31] brew_1.0-6            lattice_0.19-30

loaded via a namespace (and not attached):
[1] cluster_1.14.0 nlme_3.1-101   stats4_2.13.1  stringr_0.5     
tools_2.13.1

>
>> 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 <dwinsemius at 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 <dwinsemius at 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 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
>>>
>>>
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>>
>>        [[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



More information about the R-help mailing list