[R] Representing a statistic as a colour on a 2d plot

Jim Lemon jim at bitwrit.com.au
Thu May 10 09:49:20 CEST 2007


mister_bluesman wrote:
> Ive been getting the color.scale function to work. However, I really need to
> know is that if i have values: 0.1 0.2, 0.3, 0.4, 0.5, for example, how I
> can plot these using colours that would be different if the contents of the
> file were 0.6, 0.7, 0.8, 0.9 and 1.0. Using color.scale scales them so that
> they differ, but only relative to each other, rather than taking the actual
> value and converting them to some unique colour/colour intensity.
> 
> Many thanks
> 
There are a couple of ways to go about this. If you know that there are 
say ten possible values, you can use the color.gradient function to 
assign ten colors across a particular range. Then you would have to map 
the colors to the numbers (I would do something like creating a two 
element list of the sorted unique numbers and the colors. Then assign 
the color vector for the plot from this list.) Note that both 
color.scale and color.gradient are aimed at producing colors that 
visually represent some range like cold(blue) to hot(red). If you just 
want to get 20 easily discriminated colors and assign them to values, 
you might be better off with ColorBrewer.

Jim



More information about the R-help mailing list