[R] 3D plot

Duncan Murdoch murdoch at stats.uwo.ca
Sun Feb 21 15:28:58 CET 2010

On 18/02/2010 11:43 AM, David A.G wrote:
> Dearl list,
> can anyone point me to a function or library that can create a graph similar to the one in the following powerpoint presentation?

It could be done in rgl with a lot of work.  I don't know of a package 
where someone has already done the work.

rgl can plot triangles and quadrilaterals in 3d, but not general 
polygons.  So you'd need to decompose each chromosome sequence into a 
sequence of simpler shapes.  For example,

n <- 100
f <- rnorm(n, mean=10, sd=1)
g <- rnorm(n, mean=10, sd=1)
x <- 1:n
fn <- colorRamp(c("blue","white","red"))
color <- function(value) {
   vals <- fn(value)
   rgb(vals[,1], vals[,2], vals[,3], max=255)

m <- max(f,g)

quadx <- cbind( x[-n], x[-1], x[-1], x[-n] )
quadh <- cbind( 0, 0, f[-1], f[-n] )
quadcol <- cbind( color(0), color(0), color(f[-1]/m), color(f[-n]/m))

quads3d( as.numeric(t(quadx)), 10, as.numeric(t(quadh)), 
quadh <- cbind( 0, 0, g[-1], g[-n] )
quadcol <- cbind( color(0), color(0), color(g[-1]/m), color(g[-n]/m))
quads3d( as.numeric(t(quadx)), 20, as.numeric(t(quadh)), 

This doesn't get the colours the way the presentation had them, that 
would be a bit more work.

Duncan Murdoch

> http://bmi.osu.edu/~khuang/IBGP705/BMI705-Lecture7.ppt
> (pages 36-37)
> In order to try to explain the graph, the way I see it in R terms is something like this:
> the "p-q" axis is a vector of positions (for example, seq(0,5000000,1))
> the "Chr1-Chrx" is a vector of units, in this case chromosomes (so something like seq(1,10,1))
> the plotted data is observations for each unit at each position
> I guess the fancy gradient on the highest peaks is tougher to get (knowing I am not an R expert), but just plain blue would suffice.
> I have checked some of the graphs in the R graph gallery but I don´t think any of them would work
> Thanks in advance,
> Dave
> _________________________________________________________________
> Hotmail: Trusted email with powerful SPAM protection.
> 	[[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.

More information about the R-help mailing list