[英]Custom color scale for filled.contour heatmap with base R
I have this kind of color palette that I want to use 我有想要使用的调色板
palette <- colorRampPalette(c("darkblue", "blue", "lightblue1",
"green", "yellow", "red", "darkred"))
Illustration how my graphs look at the moment 图示目前我的图表外观
I have used filled.contour()
to plot this graph with some modifications. 我已经使用filled.contour()
来绘制此图并作一些修改。
Here's a part of the code that makes somewhat similar graph 这是一部分代码,它使图表有些相似
load("workspace.RData")
library(lubridate)
breaks <- "2 hours"
palette <- colorRampPalette(c("darkblue", "blue", "lightblue1",
"green", "yellow", "red", "darkred"))
f <- function(x) as.POSIXct(levels(cut(x, breaks)))
filled.contour(x = data$Time,
y = log10(channels),
z = df,
color.palette = palette,
plot.axes = axis(1, at = f(data$Time),
labels = format(f(data$Time), "%H:%M")))
by using data
, channels
and df
from my workspace made with save.image()
. 通过使用save.image()
从我的工作空间中获取 data
, channels
和df
。
Now the function is making the color legend on the right look like that by default. 现在,该功能使默认情况下右侧的颜色图例看起来像。 I would like to specify myself that dark blue corresponds to 0 and dark red corresponds to some user defined value for example 20 million. 我想指定自己,深蓝色对应0,深红色对应一些用户定义的值,例如2000万。
I want this because if I was to compare the graph of this data with graph of some other data, they would have exactly the same color legend. 我想要这样做是因为,如果我要将此数据的图与其他数据的图进行比较,它们将具有完全相同的颜色图例。
Tell me if I need to provide more information or anything. 告诉我是否需要提供更多信息或其他任何信息。
EDIT: 编辑:
Provided the data from my workspace as workspace.RData file. 从我的工作空间提供的数据作为workspace.RData文件。
levels
(和nlevels
)参数似乎可以很好地完成工作...我感到很愚蠢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.