JohnRos
JohnRos

Reputation: 1247

How to overlay level plots in R?

In R, say you wish to present statistical data on an image background- like in medical imaging

example produced with Mango

Each layer is a different matrix. Here is a non-sense example:

How would you go about?

Upvotes: 3

Views: 2712

Answers (1)

Greg Snow
Greg Snow

Reputation: 49640

The image function can do this, just set the transparancy of the 2nd set of colors and overlay it using add=TRUE. Any missing values will be completely transparent and you can set the alpha level for the other colors (of course your graphics device has to support partial transparancy for this to work). Here is a quick example:

A <- t(volcano)[ncol(volcano):1,]
B <- (A>160) * rnorm(prod(dim(A)) )

B[ A < 120 ] <- NA  # show some complete transparency

image(A, col=grey( seq(0,1,length.out=12) ) )  # initial plot
hc <- sub('FF$','77',heat.colors(12)) # convert heat colors to have an alpha
image(B, add=TRUE, col=hc)  # overlay the new plot

Upvotes: 3

Related Questions