在堆叠的条形图中添加组之间的间距 [英] Add spacing between groups in a stacked bar plot
问题描述
假设我有一个带有分组条形图的条形图.酒吧有一个大的小组和多个非常小的小组.组标签在组上.为了提高可读性,我想在组之间引入一定的间距.
Suppose I have a bar plot with grouped bars. Bars have one large group and multiple very small groups. Group labels are on the groups. In order to increase readability, I want to introduce some amount of spacing between groups.
我使用以下代码和图像编辑器创建了一个示例图像.
I created an example image with the following code and an image editor.
library(ggplot2)
g <- ggplot(mpg, aes(class))
g + geom_bar(aes(fill = drv)) + theme_void()
到目前为止,我仅找到有关条形间距的答案.
So far, I have only found answers regarding spacing between bars.
推荐答案
使用白色边框.更改 size
以更改间隙的宽度.请注意,条形图的顶部和底部不再能准确反映出真实的基础价值.
Use a white border. Change the size
to change the width of the gap. Note that the top and bottom of the bars no longer accurately reflect the true underlying values.
g + geom_bar(aes(fill = drv), color = 'white', size = 3) + theme_void()
这篇关于在堆叠的条形图中添加组之间的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!