删除 barplot 2 因素中条形之间的空格

Remove spaces between bars in barplot 2 factors

我有以下代码:

df=data.frame(time=as.factor(rep(0.5:9.5,each=10)),roi=rep(1:10,10),area=runif(1‌​00, 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 = 0.9, height = 0.5) + scale_fill_gradient(low="blue",high="red")

如何删除 10 rois 的条形之间的空格(我的意思是 rois 之间的空格)并使 10 条 10 rois 的条形在每个时间值连续保持。非常感谢您的帮助。

不确定这是否是您想要的,但您似乎可以更改 geom_tile 中的 height?

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

  • 而不是 geom_tileheightwidth 参数,使用 coord_fixed(ratio=r) 来控制纵横比 瓷砖(其中 r 是比率)。我在下面的示例中使用了 r=0.5。
  • 切换 xy 列,这样您就可以在 x 轴上得到 roi 而不需要 coord_flip()(您不能同时使用 coord_flip()coord_fixed() 同时出现)。
  • 设置 colour=NA 以便给定行中的每个图块之间不会有 space。
  • 设置height=0.9以在每行图块之间创建一个space。

    ggplot(data=df, aes(x=factor(roi), y=time, fill = area)) + 
      theme_minimal() + 
      coord_fixed(ratio=0.5) +
      geom_tile(colour = NA, width = 1, height = 0.9) + 
      scale_fill_gradient(low="blue",high="red")