[R] Using rgl to put a graphic beneath a plot

Duncan Murdoch murdoch at stats.uwo.ca
Sat Dec 5 13:17:41 CET 2009


On 05/12/2009 3:07 AM, Colin Wyers wrote:
> I've written a very simple bit of code to plot a trajectory using rgl:
> 
>  
> 
> x <- (c(0,-5.947,-11.496,-16.665,-21.474,-25.947,-30.116,-34.017,-37.684,-41.148,-44.435,-47.568,-50.567,-53.448,-56.223,-58.906))
> y <- (c(0,33.729,65.198,94.514,121.784,147.151,170.797,192.920,213.717,233.360,252.003,269.774,286.781,303.117,318.858,334.071))
> z <- (c(3,11.914,19.629,26.066,31.167,34.902,37.262,38.257,37.903,36.221,33.233,28.964,23.442,16.696,8.761,-0.325))
> plot3d(x,y,z, type='l',axes=FALSE, box=FALSE)
> 
>  
> 
> I have a PNG file that I want to place the plot on top of. I've arranged the image so that the point at x=282 px and y=52 px should correspond with the origin of the graph.

One way is to use the PNG file as a texture on a rectangle behind the 
line.  demo(flag) does a fairly elaborate example of this.  See 
?rgl.surface for the description of how to do it.

Another way is to use the image on the background sphere; example(bg3d) 
and demo(envmap) do this.

Duncan Murdoch




More information about the R-help mailing list