如何控制geom_tile()的高度

How to control the height of geom_tile()

使用此数据框:

df <- structure(list(region = c("AA", "BB", "CC", "DD"), event1 = c("XXX", 
"XXX", "XXX", "XXX"), value = c(3, 1, 2, 2)), row.names = c(NA, 
-4L), class = c("tbl_df", "tbl", "data.frame"))

  region event1 value
  <chr>  <chr>  <dbl>
1 AA     XXX        3
2 BB     XXX        1
3 CC     XXX        2
4 DD     XXX        2

使用此代码:

ggplot(df, aes(x = region, y = event1,  fill = value)) +
  geom_tile(height=1, colour="white", size=0.5) + 
  geom_text(aes(label = value), color = "grey20", size = 5) +
  scale_fill_gradientn(colours=  c("green","white","red"),, na.value = "transparent",
                       breaks=c(1,2,3,4),
                       labels = c("1 - A", "2 - B", "3 - C", "4 - D"),
                       limits=c(0.5,4.5))

我得到这个情节:

我想要的输出:

如何修改代码来控制方块的高度?

实现您想要的结果的一个选择是增加比例的扩展:

library(ggplot2)

ggplot(df, aes(x = region, y = event1,  fill = value)) +
  geom_tile(height=1, colour="white", size=0.5) + 
  geom_text(aes(label = value), color = "grey20", size = 5) +
  scale_y_discrete(expand = expansion(add = c(.6, 3))) +
  scale_fill_gradientn(colours=  c("green","white","red"),, na.value = "transparent",
                       breaks=c(1,2,3,4),
                       labels = c("1 - A", "2 - B", "3 - C", "4 - D"),
                       limits=c(0.5,4.5))