固定填写 geom_hex
Fixing Fill in geom_hex
我正在努力让 geom_hex 填充某个变量。我的目标是让 geom_hex 填充变量 xRV,较低的值是红色,较高的值是蓝色,但就目前情况而言,我得到的只是灰色六边形。
这是 df:
IVB <- c(10, 15, 20, 17, 17.5, 20, 17, 16.5, 21.3, 12.5, 10.9)
RelZ <- c(66, 75, 70, 67, 68.3, 67.6, 70.3, 72, 65.3, 55.6, 71)
xRV <- c(-.01, .13, -.15, .5, -.03, -.06, .07, .1, -.02, .05, .01)
miheat <- data.frame(IVB, RelZ, xRV)
这是我一直在运行但没有用的代码:
library(ggplot2)
library(hexbin)
ggplot(miheat, aes(x = RelZ, y = IVB)) + geom_hex(aes(fill = xRV)) + scale_fill_gradient2(low = "red" , mid = "white" , high = "blue", space = "Lab")
Here's what the output looks like when I run the code above on all of the df
你在你的问题中所做的很接近。而不是使用 fill
你应该做的是使用 weight
library(ggplot2)
library(hexbin)
ggplot(miheat,aes(x = RelZ, y = IVB, weight = xRV)) + geom_hex() + scale_fill_gradient2(low = "red" , mid = "white" , high = "blue", space = "Lab", midpoint = 0)
我正在努力让 geom_hex 填充某个变量。我的目标是让 geom_hex 填充变量 xRV,较低的值是红色,较高的值是蓝色,但就目前情况而言,我得到的只是灰色六边形。
这是 df:
IVB <- c(10, 15, 20, 17, 17.5, 20, 17, 16.5, 21.3, 12.5, 10.9)
RelZ <- c(66, 75, 70, 67, 68.3, 67.6, 70.3, 72, 65.3, 55.6, 71)
xRV <- c(-.01, .13, -.15, .5, -.03, -.06, .07, .1, -.02, .05, .01)
miheat <- data.frame(IVB, RelZ, xRV)
这是我一直在运行但没有用的代码:
library(ggplot2)
library(hexbin)
ggplot(miheat, aes(x = RelZ, y = IVB)) + geom_hex(aes(fill = xRV)) + scale_fill_gradient2(low = "red" , mid = "white" , high = "blue", space = "Lab")
Here's what the output looks like when I run the code above on all of the df
你在你的问题中所做的很接近。而不是使用 fill
你应该做的是使用 weight
library(ggplot2)
library(hexbin)
ggplot(miheat,aes(x = RelZ, y = IVB, weight = xRV)) + geom_hex() + scale_fill_gradient2(low = "red" , mid = "white" , high = "blue", space = "Lab", midpoint = 0)