【发布时间】:2018-08-11 12:02:07
【问题描述】:
这是我尝试修改的起始示例:
library(reshape2)
data <- mtcars[, c(1,3,4,5,6,7)]
cormat <- round(cor(data),2)
melted_cormat <- melt(cormat, na.rm = TRUE)
ggplot(
data = melted_cormat,
aes(Var1, Var2, fill=value)
) +
geom_tile() +
geom_text(
aes(Var2, Var1, label = value)
) +
scale_fill_gradient2(
low = 'red',
high = 'blue',
mid = 'white',
midpoint = 0, # <-- look at this
limit = c(-1, 1)
)
这段代码创建了一个情节:
但是当我将唯一的中点更改为midpoint = -0.5 时,情节看起来像:
在我看来,输出不正确,因为我明确说明了low = 'red',并且图中的最低值颜色介于红色和白色之间。
我正在寻找一种解决方案,如何保持 midpoint = -0.5 以及从 -1(红色)到 -0.5(白色)的完整渐变。
【问题讨论】:
标签: r ggplot2 data-visualization