

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 chart using ggplot2 with labels at inside end of the bars in R?
To create a horizontal bar chart using ggplot2 package, we need to use coord_flip() function along with the geom_bar and to add the labels geom_text function is used. These two functions of ggplot2 provides enough aesthetic characteristics to create the horizontal bar chart and put the labels at inside end of the bars.
Example
x<-c("A","B","C","D") freq<-c(24,26,27,23) df<-data.frame(x,freq) df
Output
x freq 1 A 24 2 B 26 3 C 27 4 D 23
library(ggplot2) ggplot(df,aes(x,freq))+geom_bar(stat="identity")+coord_flip()
Output
> ggplot(df,aes(x,freq,label=freq))+geom_bar(stat="identity")+geom_text(size=5,hjust=1.5)+coord_flip()
Output
> ggplot(df,aes(x,freq,label=freq))+geom_bar(stat="identity")+geom_text(size=10,hjust=1.5)+coord_flip()
Output
- Related Questions & Answers
- How to create a bar chart using ggplot2 with dots drawn at the center of top edge of the bars in R?
- How to create bar chart using ggplot2 with chart sub-title 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 horizontal bar graph using ggplot2 in R?
- How to create the bar chart with ggplot2 using color brewer in R?
- How to create horizontal stacked bar chart using ggvis in R?
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- How to create a bar graph using ggplot2 without horizontal gridlines and Y-axes labels in R?
- How to create plotly bar chart with values on top of bars in R?
- How to create a bar chart for single vector using ggplot2 in R?
- How to reverse the bars of a bar plot a using ggplot2 in R?
- How to create the stacked bar plot using ggplot2 in R with labels on the plot?
- How to create bar plot of means with error bars of standard deviations using ggplot2 in R?
- Python Pandas - Create a Horizontal Bar Chart
- How to change the color of bars of a bar plot using ggplot2 in R?
Advertisements