反转日历上的颜色顺序

时间:2018-08-29 22:31:40

标签: r heatmap

我想知道如何反转calendarHeatmap的颜色,以使白色= 0,最暗的蓝色= 120

calendarHeat(myd$date1, myd$heatvar, varname="VAR name", ncolors=5,color="w2b" )

enter image description here

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")

1 个答案:

答案 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")

enter image description here

数据:

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))