- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to increase the space between bars of a bar plot using ggplot2 in R?
When a bar plot is created then the distance or space between bars is equal but sometimes the width of the bar is large, therefore, it becomes a little difficult to understand the difference between those bars especially in cases when the data values are not very much different from each other. To overcome this visualization problem, we can create a bar plot with some space between the bars and it can be done with the help of width argument of geom_bar in ggplot2.
Example
Consider the below data frame −
x<-c("X1","X2","X3","X4","X5") Frequency<-c(42,35,39,45,49) df<-data.frame(x,Frequency) df x Frequency 1 X1 42 2 X2 35 3 X3 39 4 X4 45 5 X5 49 library(ggplot2) ggplot(df,aes(x,Frequency))+geom_bar(stat='identity')
Output
Now to increase the space between bars can be done as follows −
ggplot(df,aes(x,Frequency))+geom_bar(stat='identity',width=0.3)
Output
- Related Articles
- How to reverse the bars of a bar plot a using ggplot2 in R?
- How to change the color of bars of a bar plot using ggplot2 in R?
- Increase the space between facets in a facetted plot created using ggplot2 in R.
- How to create a bar plot in R with label of bars on top of the bars using ggplot2?
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- How to increase the space between horizontal legends using ggplot2 in R?
- How to create bar plot of means with error bars of standard deviations using ggplot2 in R?
- How to change the thickness of the borders of bars in bar plot created by using ggplot2 in R?
- Change the starting point of bars in bar plot for a ggplot2 graph in R.
- How to create transparent bar plot using ggplot2 in R?
- How to fill bars of a bar plot created using ggplot2 with colors based on frequency?
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to increase the distance between boxplots using ggplot2 in R?
- How to create a bar plot using ggplot2 with one bar having black border in R?
- How to create the stacked bar plot using ggplot2 in R with labels on the plot?

Advertisements