[R] lattice centre a diverging colour scale
baptiste Auguié
baptiste.auguie at googlemail.com
Thu Sep 23 10:43:09 CEST 2010
Great, I don't know how I missed that, thanks!
baptiste
On Sep 23, 2010, at 10:39 AM, Deepayan Sarkar wrote:
> On Thu, Sep 23, 2010 at 12:33 PM, baptiste auguie
> <baptiste.auguie at googlemail.com> wrote:
>> Dear list,
>>
>> I'm using lattice::levelplot to plot a coloured image of 3D data. The
>> range of the z values goes from negative to positive, but is not
>> exactly centred around 0. I would however like to map a diverging
>> colour scale with white falling exactly at 0, and both extremes being
>> symmetrical in the legend to better contrast the opposite change in
>> colour saturation. The following dummy example illustrates my problem,
>>
>>
>> library(lattice)
>> d <- transform(expand.grid(x=seq(0, 10, length=100),
>> y=seq(0, 10, length=100)),
>> z = sin(x/pi)*cos(0.5*y/pi) - 0.2)
>>
>> levelplot(z~x*y, data=d,
>> panel=panel.levelplot.raster,
>> cuts = 100, interpolate = TRUE)
>>
>> The colour scale goes from -0.3 to 0.9 with a middle (white) value of
>> 0.3 approximately. I'd like it to be from -1 (most saturated blue) to
>> 1 (most saturated pink), say, with 0 being white.
>>
>> I read the entry in ?levelplot and in ?level.colors but could not find
>> a solution to this particular case.
>
> Specify the cut-points explicitly:
>
> levelplot(z~x*y, data=d, panel = panel.levelplot.raster, at =
> do.breaks(c(-1, 1), 100))
>
> -Deepayan
More information about the R-help
mailing list