- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 create a horizontal bar graph using ggplot2 in R?
Making comparisons is bit easier through horizontal bar graphs as compared to the vertical bar graphs in cases where the labels for the categories have large names. Because a large name for the labels of a vertical bar graph is likely to mix with the other labels and therefore, the reading of these labels become difficult for the viewer. To solve this problem, we can draw a bar graph and flip it with coord_flip() in ggplot2.
Consider the below data frame −
Size <-c("Small","Medium","Large") Frequency <-c(42,49,47) df <-data.frame(Size,Frequency) df
Size Frequency 1 Small 42 2 Medium 49 3 Large 47 > library(ggplot2)
Creating vertical bar graph −
Creating horizontal bar graph −
- Related Articles
- How to create a bar graph using ggplot2 without horizontal gridlines and Y-axes labels in R?
- How to create a dashed horizontal line in a ggplot2 graph in R?
- How to create horizontal legend using ggplot2 in R?
- How to create a horizontal line in ggplot2 graph with larger width in R?
- How to create a horizontal line in ggplot2 graph with different color in R?
- How to create transparent bar plot using ggplot2 in R?
- How to create a horizontal bar plot using barplot function in R?
- How to create a horizontal bar chart using ggplot2 with labels at inside end of the bars in R?
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to create horizontal stacked bar chart using ggvis in R?
- How to create a bar chart for single vector using ggplot2 in R?
- How to create a bar plot using ggplot2 with one bar having black border in R?
- How to create bar plot with log values using ggplot2 in R?
- Create a graph without background panel using ggplot2 in R.
- How to create a stacked bar plot with vertical bars in R using ggplot2?