Skip to content

Changing colours for heatmap plot

2 messages · John Wasige, Jim Lemon

#
?Dear community,

Could somebody help on how I can change the colour for this plot in the
heatmap plot script below to something like c("green", "green", "black",
"green", "green", "black", "black", "green", "green", "black"):

######
library(gplots)
library(lattice)

### loading data
data <- read.csv('D:/Londa/MyData.csv')
rowcolNames <- list(as.character(1980:2009), month.abb)
air_data <- matrix(data ,
                   ncol = 12,
                   byrow = TRUE,
                   dimnames = rowcolNames)

print(levelplot(air_data,
                col.regions=heat.colors,
                xlab = "year",
                ylab = "month",
                main = "New #1"))?

##########

Thanks for your help

John
1 day later
#
Hi John,
As heat.colors is a function that returns a vector of colors specified
by the "n" argument, you could write something like this:

my_custom_colors<-function(n,color_vector="lightgray")
return(rep(color_vector,length.out=n)))

and then pass the desired color vector to it:

green_n_black<-c("green", "green", "black",
"green", "green", "black", "black", "green", "green", "black")
my_custom_colors(12,green_n_black)
my_custom_colors(4,green_n_black)

Jim
On Fri, Jun 5, 2015 at 10:33 PM, John Wasige <johnwasige at gmail.com> wrote: