[R] Adding points to a wireframe with conditioning variable

Mark Lyman mark.lyman at gmail.com
Thu Jul 5 21:40:50 CEST 2007


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 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

Thank 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



More information about the R-help mailing list