我想知道如何反转calendarHeatmap的颜色,以使白色= 0,最暗的蓝色= 120
calendarHeat(myd$date1, myd$heatvar, varname="VAR name", ncolors=5,color="w2b" )
源
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")
答案 0 :(得分:1)
我们如何复制calendarHeat
函数的源代码,然后反转w2b
调色板,就像这样:
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")
数据:
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))