- 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 reverse the bars of a bar plot a using ggplot2 in R?
The bars of a bar plot are generally vertical from bottom to top but we can reverse them as well. Although, this is not a normal practice but we can do it if we want to. For this purpose, we will have to reverse the values on the Y-axis, as a result the bars will be reversed. It can be achieved by using scale_y_continuous.
Example
Consider the below data frame −
Salary_Group <-c("A","B","C","D","E") Attendance <-c(78,82,90,95,85) df <-data.frame(Salary_Group,Attendance) df
Output
Salary_Group Attendance 1 A 78 2 B 82 3 C 90 4 D 95 5 E 85
Creating a simple bar plot −
Example
library(ggplot2) ggplot(df,aes(Salary_Group,Attendance))+geom_bar(stat="identity")
Output
Reversing the bars of the plot −
Example
ggplot(df,aes(Salary_Group,Attendance))+geom_bar(stat="identity")+scale_y_continuous(trans="reverse")
Output
- Related Articles
- How to change the color of bars of a bar plot using ggplot2 in R?
- How to increase the space between bars of a bar plot 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 create bar plot of means with error bars of standard deviations using ggplot2 in R?
- Change the starting point of bars in bar plot for a ggplot2 graph in R.
- How to change the thickness of the borders of bars in bar plot created by 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 create transparent bar plot using ggplot2 in R?
- How to create a bar plot using ggplot2 with one bar having black border in R?
- How to change the Y-axis values in a bar plot using ggplot2 in R?
- How to change the bars color to grey shade of a bar graph created by using ggplot2 in R?
- How to manage top and bottom spaces of a bar plot using ggplot2 in R?
- How to change the automatic sorting of X-axis of a bar plot using ggplot2 in R?

Advertisements