heihei
heihei

Reputation: 1

How can I change bar distance using R ggplot2?

I am plotting a bar plot with ggplot2. I want the bar width is very small,but the distance between the bars is very large, like the picture, how can I change the distance? enter image description here

Upvotes: 0

Views: 271

Answers (2)

Susan Switzer
Susan Switzer

Reputation: 1922

This question has been aswered at ggplot2 : How to reduce the width AND the space between bars with geom_bar

library(tidyverse)

ggplot(data = iris,
       mapping = aes(x = Species, 
                     y = Sepal.Length))+
  geom_col(width = .5)+
  theme(aspect.ratio = 3/2)

Without aspect ratio code: enter image description here

With aspect ratio code: enter image description here

Upvotes: 0

Elias
Elias

Reputation: 736

Here is an example ggplot(data = df, aes(x=X, y=Y, fill=F)) + geom_bar(width = 0.5, position = position_dodge(width = 0.8))

position_dodge(width = 0.8) is for the space between the bars. width = 0.5 is an example for the withd of the bar itself.

Let me know if it worked :)

Upvotes: 0

Related Questions