On 04/28/2012 12:58 PM, nhbnhb wrote:
Hi~I'm new to R. I'm following these two tutorials to make a tree map, but
the color scale isn't quite what I wanted.
For map of the market, the color scale starts from 0(red) to max(green),
what I wanted is 0(Green)-1(Red)-max(green). What's the easiest way to
achieve this kind of divergent color scale?
How shall I make my own palette and use it in the map.market or tree map
function?
Hi nhbnhb,
Here's one way to do it:
library(plotrix)
# get some values from 0 to 5
values<-runif(20,0,5)
# set everything to the color for 1
value_colors<-rep("red",20)
# get colors for all the values less than 1, but drop the first
value_colors[values<1]<-
color.scale(c(1,values[values<1]),extremes=c("green","red"))[-1]
# get colors for all the values greater than 1, drop the first
value_colors[values>1]<-
color.scale(c(1,values[values>1]),extremes=c("green","red"))[-1]
Jim
______________________________________________
R-help@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.