[R] Changing colours for heatmap plot

Jim Lemon drjimlemon at gmail.com
Sun Jun 7 07:57:57 CEST 2015


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:
> 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
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list