Mark Lyman
2007-Jul-05 14:53 UTC
[R] Adding points to a wireframe with conditioning variable
I would like to add points to a wireframe but with a conditioning variable. I found a solution for this without a conditioning variable here, http://finzi.psych.upenn.edu/R/Rhelp02a/archive/65321.html. Does anyone know how to plot a wireframe conditioned on a variable and add the points conditioned on the same variable, similar to the solution at the link above?
Deepayan Sarkar
2007-Jul-05 18:24 UTC
[R] Adding points to a wireframe with conditioning variable
On 7/5/07, Mark Lyman <mark.lyman at gmail.com> wrote:> I would like to add points to a wireframe but with a conditioning variable. I > found a solution for this without a conditioning variable here, > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/65321.html. Does anyone know > how to plot a wireframe conditioned on a variable and add the points > conditioned on the same variable, similar to the solution at the link above?Depends on what form you have your points in. Inside a panel function, packet.number() will give you the packet number in sequential order (column major order if you think of the conditioning variables as defining a multiway cross-tabulation), and which.packet() will give you a vector with the current level of each conditioning variable. You can use these to extract the appropriate subset of points. -Deepayan
Mark Lyman
2007-Jul-05 19:40 UTC
[R] Adding points to a wireframe with conditioning variable
Deepayan Sarkar <deepayan.sarkar <at> gmail.com> writes:> > On 7/5/07, Mark Lyman <mark.lyman <at> gmail.com> wrote: > > I would like to add points to a wireframe but with a conditioningvariable. I> > found a solution for this without a conditioning variable here, > > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/65321.html. Does anyoneknow> > how to plot a wireframe conditioned on a variable and add the points > > conditioned on the same variable, similar to the solution at the linkabove?> > Depends on what form you have your points in. Inside a panel function, > packet.number() will give you the packet number in sequential order > (column major order if you think of the conditioning variables as > defining a multiway cross-tabulation), and which.packet() will give > you a vector with the current level of each conditioning variable. You > can use these to extract the appropriate subset of points. > > -DeepayanThank you Deepayan. I modified the panel function you wrote in the post referenced above according to your suggestion. Here is the panel function, I came up with panel.3dwire.points <- 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, ...) pts.sub <- subset(pts, g==levels(g)[which.packet()]) xx <- xlim.scaled[1] + diff(xlim.scaled)*(pts.sub$x - xlim[1])/diff (xlim) yy <- ylim.scaled[1] + diff(ylim.scaled)*(pts.sub$y - ylim[1])/diff (ylim) zz <- zlim.scaled[1] + diff(zlim.scaled)*(pts.sub$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, ...) } where pts is a dataframe with the three dimensional points (x,y,z) and the conditioning variable g. Mark