Reputation: 5458
I would like to know how to reverse the color of this calendarHeatmap so that white = 0 and the darkest blue = 120
calendarHeat(myd$date1, myd$heatvar, varname="VAR name", ncolors=5,color="w2b" )
source
st <- as.Date("2010-2-17")
en <- as.Date("2013-4-7")
datell <- seq(st, en, "1 day")
myd <- data.frame (date1 = datell, heatvar = rnorm (length (datell), 50, 20))
require(lattice)
require(chron)
require(grid)
calendarHeat(myd$date1, myd$heatvar, varname="VAR name", ncolors=5, color="w2b")
Upvotes: 1
Views: 99
Reputation: 4768
How about we copy the source code of the calendarHeat
function and then reverse the w2b
color palette, something like:
require(lattice)
require(chron)
require(grid)
# Grab the source code
source("https://raw.githubusercontent.com/iascchen/VisHealth/master/R/calendarHeat.R")
# Create a copy of the heatmap function
calendarHeat2 <- calendarHeat
# Reverse the color palette for the copied function
body(calendarHeat2)[[23]] <- substitute(w2b <- rev(c("#045A8D", "#2B8CBE", "#74A9CF", "#BDC9E1", "#F1EEF6")))
# Plot!
calendarHeat2(myd$date1, myd$heatvar, varname="VAR name", ncolors=5, color="w2b")
Data:
st <- as.Date("2010-2-17")
en <- as.Date("2013-4-7")
datell <- seq(st, en, "1 day")
myd <- data.frame (date1 = datell, heatvar = rnorm(length(datell), 50, 20))
Upvotes: 1