Mike MacFerrin
2012-Jan-06 03:28 UTC
[R] Can levelplot colorkeys display a logarithmic scale evenly?
I'm using the {lattice} "levelplot" function to make a (more or less) 2-d histogram, and for the most part it's working fine with my data. However, I can't get the color key to do what I need. I can give it labels and custom cutoffs, but my cutoff lines (and hence my labels) aren't evenly spaced, instead they're more-or-less logarithmic, starting at [0,20,50,100...] and continuing on up to 5 million. Levelplot scales the ticks/labels linearly on the color key, leaving most my labels scrunched down atop each other at the bottom and only the last few (..."500K","1M","2M","5M") really visible on the rest of the key. I want each gap (no matter its numerical range) to occupy one evenly-spaced "block" on the color key, so they're all readable by the user. I want it to display value on a logarithmic scale (0,1,10,100,1000,...). The colorkey only seems to support linear scales (0,2,4,6,8,10,...), at least by default, and I don't see any options in the help to change that default. Does levelplot support this? Or am I destined to draw the colorkey manually (very painfully using polygon calls and user coordinates)? Or are there other levelplot-like functions that would facilitate this? Any help is appreciated, - Mike
Jean V Adams
2012-Jan-09 20:06 UTC
[R] Can levelplot colorkeys display a logarithmic scale evenly?
Mike MacFerrin wrote on 01/05/2012 09:28:56 PM:> I'm using the {lattice} "levelplot" function to make a (more or less)2-d> histogram, and for the most part it's working fine with my data.However, I> can't get the color key to do what I need. I can give it labels andcustom> cutoffs, but my cutoff lines (and hence my labels) aren't evenly > spaced, instead > they're more-or-less logarithmic, starting at [0,20,50,100...] and > continuing on > up to 5 million. > > Levelplot scales the ticks/labels linearly on the color key, leavingmost my> labels scrunched down atop each other at the bottom and only the lastfew> (..."500K","1M","2M","5M") really visible on the rest of the key. Iwanteach> gap (no matter its numerical range) to occupy one evenly-spaced > "block" on the > color key, so they're all readable by the user. I want it to > display value on a > logarithmic scale (0,1,10,100,1000,...). The colorkey only seems tosupport> linear scales (0,2,4,6,8,10,...), at least by default, and I don't seeany> options in the help to change that default. > > Does levelplot support this? Or am I destined to draw the colorkeymanually> (very painfully using polygon calls and user coordinates)? Or are > there other > levelplot-like functions that would facilitate this? Any help isappreciated,> > - MikeHere's one workaround ... library(lattice) dat <- expand.grid(x=15*runif(100), y=100*runif(100)) dat$z <- exp(dat$x) + dat$y^2 dat$lz <- log10(dat$z) levelplot(lz ~ x * y, dat, at=0:7, colorkey=list(labels=paste("10^", 0:7, sep=""))) Jean [[alternative HTML version deleted]]