删除 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(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 = 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_tile
的 height
和 width
参数,使用 coord_fixed(ratio=r)
来控制纵横比
瓷砖(其中 r
是比率)。我在下面的示例中使用了 r=0.5。
- 切换
x
和 y
列,这样您就可以在 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")
我有以下代码:
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 = 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_tile
的height
和width
参数,使用coord_fixed(ratio=r)
来控制纵横比 瓷砖(其中r
是比率)。我在下面的示例中使用了 r=0.5。 - 切换
x
和y
列,这样您就可以在 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")