首页 > 解决方案 > 如何将geom_bar的宽度调整为相同的宽度

问题描述

 TEMP %>%   ggplot(aes(x= Count,y=reorder(Species,Count))) + geom_col(position = "dodge") + ggtitle("Insects abundance during 2017~2019") + ylab("Insects") + xlab("Mean Number")   + facet_wrap(~ CLASS,ncol = 1,scales = 'free') + theme_bw()

在此处输入图像描述

我想让顶部面板和底部面板具有相同的宽度条。但即使我在geom_col(width = .5). 它们的宽度仍然不同。有什么问题。感谢所有关心我问题的人。谢谢。

标签: rggplot2

解决方案


由于您没有发布带有数据的代表,我将只使用 mtcars 数据集。

space参数 in允许每个方面的facet_grid()宽度由 x 或 y 值的数量确定。

没有space = "free_y"

library(tidyverse)

mtcars %>% ggplot(aes(y = factor(carb))) + 
        geom_bar(width = 0.5) + 
        facet_grid(am~., scales = "free")

在此处输入图像描述

space = "free_y"

library(tidyverse)

mtcars %>% ggplot(aes(y = factor(carb))) + 
        geom_bar(width = 0.5) + 
        facet_grid(am~., scales = "free", space = "free_y")

在此处输入图像描述


推荐阅读