ggplot2条形图删除轴标签和y轴上0计数之间不必要的距离[重复]

问题描述 投票:1回答:1

我有一个简单的条形图,其中x是类别变量1 - 9的级别,z是每个级别的计数。但是底部有一个距离(标记为红色),我想删除它。我无法在网上找到有用的提示。任何人都可以帮我吗?先感谢您!

ggplot(data = my_data,aes(x = factor(degree)), stat = "count") + geom_bar()

r ggplot2 geom-bar
1个回答
1
投票

expand=函数中的scale_*参数控制绘图边缘周围的额外空间。

ggplot(data = mtcars,aes(x = factor(cyl)), stat = "count") +
    geom_bar() +
    scale_y_discrete()

enter image description here

ggplot(data = mtcars,aes(x = factor(cyl)), stat = "count") +
    geom_bar() +
    scale_y_discrete(expand = c(0,0))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.