- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 align the bars of a barplot with the X-axis using ggplot2 in R?
The bar plot is created with geom_bar function but there always exist some space between the bars and the X-axis labels. If we want to reduce that space or completely remove it we need to use scale_y_continuous function by defining expand argument for former and scale_y_continuous(expand=c(0,0)) for latter.
Consider the below data frame −
set.seed(888) x<-c("S1","S2","S3","S4") y<-c(24,27,25,28) df<-data.frame(x,y) df
x y 1 S1 24 2 S2 27 3 S3 25 4 S4 28
Loading ggplot2 package and creating bar plot of y −
Creating the bar plot without space between X-axis labels and the bars −
- How to display negative labels below bars in barplot using ggplot2 in R?
- How to change the color of X-axis label using ggplot2 in R?
- How to X-axis labels to the top of the plot using ggplot2 in R?
- How to change the color of bars in base R barplot?
- How to create a bar plot in R with label of bars on top of the bars using ggplot2?
- How to increase the X-axis labels font size using ggplot2 in R?
- How to create a barplot with one of the bars having different color in R?
- How to change the automatic sorting of X-axis of a bar plot using ggplot2 in R?
- How to change the space between bars in a barplot in R?
- How to reverse the X-axis labels of scatterplot created by using ggplot2 in R?
- How to reverse the bars of a bar plot a using ggplot2 in R?
- How to set the X-axis labels in histogram using ggplot2 at the center in R?
- How to change the orientation and font size of x-axis labels using ggplot2 in R?
- How to change the color of bars of a bar plot using ggplot2 in R?
- How to write partial title of X-axis in italics using ggplot2 of R?