heatmap - filled.contour() in R: nonlinear key range -
i using filled.contour() plot data stored in matrix. data generated (highly) non-linear function, hence distribution not uniform @ , range large.
consequently, have use option "levels" fine tune plot. however, filled.contour() not use these custom levels make appropriate color key heat map, find quite surprising.
here simple example of mean:
x = c(20:200/100) y = c(20:200/100) z = as.matrix(exp(x^2)) %*% exp(y^2) filled.contour(x=x,y=y,z=z,color.palette=colorramppalette(c('green','yellow','red')),levels=c(1:60/3,30,50,150,250,1000,3000))
as can see, color key produced code above pretty useless. use sort of projection (perhaps sin(x) or tanh(x)?), upper range not over-represented in key (in linear way).
at point, to:
1) know if there simple/obvious missing, e.g.: option make "key range adapting" automagically; 2) seek suggestions/help on how myself, should answer 1) negative.
thanks lot!
ps: apologize english, far perfect. please let me know if need me clarify anything.
i feel frustration. never found way filled contour
, have reverted using image
, adding own scale separate plot. wrote function image.scale
out (link). below example of how can supply log-transform scale in order stretch out small values - label scale non-log-transformed values labels:
example:
source("image.scale.r") # http://menugget.blogspot.de/2011/08/adding-scale-to-image-plot.html x = c(20:200/100) y = c(20:200/100) z = as.matrix(exp(x^2)) %*% exp(y^2) pal <- colorramppalette(c('green','yellow','red')) breaks <- c(1:60/3,30,50,150,250,1000,3000) ncolors <- length(breaks)-1 labs <- c(0.5, 1, 3,30,50,150,250,1000,3000) #x11(width=6, height=6) layout(matrix(1:2, nrow=1, ncol=2), widths=c(5,1), heights=c(6)) layout.show(2) par(mar=c(5,5,1,1)) image(x=x,y=y,z=log(z), col=pal(ncolors), breaks=log(breaks)) box() par(mar=c(5,0,1,4)) image.scale(log(z), col=pal(ncolors), breaks=log(breaks), horiz=false, xlab="", ylab="", xaxt="n", yaxt="n") axis(4, at=log(labs), labels=labs) box()
Comments
Post a Comment