- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 create a bar plot in R with label of bars on top of the bars using ggplot2?
There are multiple ways to represent a chart, specifically a bar plot is represented with so many variations. We can also include bar labels in a bar plot so that the viewer can easily understand the frequency of the categories for bars. To put the labels on top of the bars in a bar plot we can use vjust = 0 with geom_text in ggplot2.
Example
Consider the below data frame −
df<-data.frame(x=factor(c("Male","Female")),Frequency=c(24,28)) df
Output
x Frequency 1 Male 24 2 Female 28
Loading ggplot2 and creating the simple bar plot without bar labels −
library(ggplot2) ggplot(df,aes(x,Frequency))+geom_bar(stat="identity")
Output
Creating the bar plot with bars label −
ggplot(df,aes(x,Frequency))+geom_bar(stat="identity")+ + geom_text(aes(label=Frequency),vjust=0)
Output
- Related Articles
- 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?
- How to reverse the bars of a bar plot a using ggplot2 in R?
- 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 plotly bar chart with values on top of bars 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 fill bars of a bar plot created using ggplot2 with colors based on frequency?
- How to create a bar plot with bars for missing values in R?
- How to create a horizontal bar chart using ggplot2 with labels at inside end of the bars in R?
- How to change the thickness of the borders of bars in bar plot created by using ggplot2 in R?
- Change the starting point of bars in bar plot for a ggplot2 graph in R.
- How to create multiple bar plots for varying categories with same width bars using ggplot2 in R?
- How to create the stacked bar plot using ggplot2 in R with labels on the plot?
- How to create histogram like plot with different color of bars in R?

Advertisements