R 中具有两个渐变颜色的因素的条形图

Bar plot with two factors with gradient color in R

我有一个这样的数据框:

df = data.frame(time = rep(0.5:9.5, each = 10), roi = rep(1:10, 10), area = runif(100, 5.0, 7.5))

我想绘制一个图,其中包含 10 个条形图,每个条形图包含 timeroi 的 10 个值。在这种情况下,x 轴将是 roi,y 轴将是 timearea 的值将以渐变颜色的条形显示(最高 = 白色,最低 =黑色的)。 y 轴从 0.5 顶部反转到 9.5 底部,条形宽度为 2.

预期的数字看起来像 this image.

我期待着回复,感谢您的所有帮助。

这是你想要的吗?

df=data.frame(time=as.factor(rep(0.5:9.5,each=10)),roi=rep(1:10,10),area=runif(100, 5.0, 7.5))

df$time <- factor(df$time, levels=rev(levels(df$time)))

ggplot(data=df, aes(y=factor(roi), x=time, fill = area)) +
  theme_minimal()  + coord_flip() +
  geom_tile(colour = "white", width = .9, height = 1) + 
  scale_fill_gradient(low="blue",high="red")