0

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

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
heihei
  • 1
  • 3
    Welcome to stack overflow. It’s easier to help if you make your question reproducible: include a minimal dataset in the form of an object for example if a data frame as df <- data.frame(…) where … is your variables and values or use dput(head(df)). Include the code you have tried. These links should be of help: [mre] and [ask] – Peter Jul 01 '20 at 14:48
  • Does this answer your question? [ggplot2 : How to reduce the width AND the space between bars with geom\_bar](https://stackoverflow.com/questions/50077342/ggplot2-how-to-reduce-the-width-and-the-space-between-bars-with-geom-bar) – tjebo Jul 01 '20 at 16:24

2 Answers2

0

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 :)

Elias
  • 726
  • 8
  • 20
  • No,this is not what i want.what i want is that the X -axis xticks is can be change by set specific number so that the space between bars is very larger or smaller.Thank you . – heihei Jul 02 '20 at 03:49
0

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

Susan Switzer
  • 1,531
  • 8
  • 34