[R] adjusting levelplot color scale to data

David Winsemius dwinsemius at comcast.net
Mon Nov 7 06:10:21 CET 2011


On Nov 6, 2011, at 10:08 PM, Lanna Jin wrote:

> Hi guys,
>
> I have a matrix with values varying from approximately -0.7 to 0.33  
> that I
> want to create a heatmap/levelplot with.
>
> When I execute the levelplot function for my matrix, I end up  
> getting colors
> that are adjusted to the max and min rather than around 0. In other  
> words,
> ideally I would like to have a color ramp that goes from red (negative
> number), to white (0), to blue (positive); however, right now the  
> value 0 is
> in the blue.
>
> Any insight on how to address this problem?


?levelplot  # which leads to"
?level.colors  # which in turn leads to:
? colorRamp

levelplot(as.matrix(dat), at=seq( -.8, .4, length=31),  
col=color.palette(30) )


And next time, please post the output of dput rather than a mangled  
print() output.
-- 
David.
>
> Thanks in advance!
>
> example...
> my matrix "y" looks something like this
>                 A                 B                      C
> D                    E
>  row1         -0.5046406 -0.021579587    -0.4419101 -0.2999195330
> -0.4845047
>  row2         -0.3070091 -0.059065936     0.3329806 -0.0519335420
> -0.5766368
>  row3         -0.7271707  0.073282855    -0.3181990 -0.2485017700
> -0.5732781
>  row4          0.3329806 -0.017762750    -0.1513197 -0.1016354970
> 0.2528442
>
> levelplot(y) yields a color scale from red (-0.8 to 0.2) to blue  
> (0.2 to
> 0.4)
> I'd want the color scale to be from red (-0.8 to 0) to blue (0 to 0.4)
>
>
>
> -----
> Lanna
> --
> View this message in context: http://r.789695.n4.nabble.com/adjusting-levelplot-color-scale-to-data-tp3997342p3997342.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list