- 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 change the order of bars in bar chart in R?
This can be done by setting the levels of the variable in the order we want.
Example
> data <- data.frame(Class=c("Highschool","Highschool","Graduate","Graduate", "Graduate","Graduate","Masters","Masters","Masters","PhD"))
Setting the levels in decreasing order
> data <- within(data, Class <- factor(Class, levels=names(sort(table(Class), decreasing=TRUE)))) > library(ggplot2) > ggplot(data, aes(x = Class)) + geom_bar()
Setting the levels in increasing order
> data <- within(data, Class <- factor(Class, levels=names(sort(table(Class), decreasing=TRUE)))) > ggplot(data, aes(x = Class)) + geom_bar()
- Related Articles
- How to determine the order of bars in a matplotlib bar chart?
- How to decrease the width of bars for plotly bar chart in R?
- How to sort bars in increasing order in a bar chart in matplotlib?
- How to create plotly bar chart with values on top of bars in R?
- How to change the color of bars of a bar plot using ggplot2 in R?
- How to remove gaps between bars in Matplotlib bar chart?
- How to Adjust a Bar Chart to Make the Bars Wider in Excel?
- How to change the thickness of the borders of bars in bar plot created by using ggplot2 in R?
- How to create a horizontal bar chart using ggplot2 with labels at inside end of the bars in R?
- Change the starting point of bars in bar plot for a ggplot2 graph in R.
- How do I get all the bars in a Matplotlib bar chart?
- How to change the bars color to grey shade of a bar graph created by using ggplot2 in R?
- How to create a bar chart using ggplot2 with dots drawn at the center of top edge of the bars in R?
- How to change the color of bars in base R barplot?
- How to sort bars in a bar plot in ascending order (Matplotlib)?

Advertisements