- 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 create a bar plot with bars for missing values in R?
To create a bar plot in R, we can use barplot function but if there exist some missing values in the data then we can use ggplot2 package. For example, if we have a data frame having two vectors say x and y, x containing categorical values with NA as one of the values and y having counts/frequency for each of the categories then the bar plot will be created by using the command ggplot(df,aes(x,y))+geom_bar(stat="identity").
Example
Consider the below data frame −
> x<-c("A","B",NA) > y<-c(24,21,45) > df<-data.frame(x,y) > df
Output
x y 1 A 24 2 B 21 3 <NA> 45
Creating bar plot using barplot function −
> barplot(y~x,data=df)
Output
Loading ggplot2 package and creating bar plot using geom_bar function of ggplot2 package −
> library(ggplot2) > ggplot(df,aes(x,y))+geom_bar(stat="identity")
Output
- Related Articles
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- How to create a bar plot in R with label of bars on top of the bars using ggplot2?
- How to create plotly bar chart with values on top of bars in R?
- How to create bar plot with log values using ggplot2 in R?
- How to create bar plot with positive and negative values in R?
- How to create bar plot of means with error bars of standard deviations using ggplot2 in R?
- How to convert a column with missing values to binary with 0 for missing values in R?
- How to create horizontal lines for each bar in a bar plot of base R?
- How to create the plot of a vector that contains missing values by adding the missing values in base R?
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to create bar plot in base R with different limits for Y-axis?
- How to reverse the bars of a bar plot a using ggplot2 in R?
- How to create multiple bar plots for varying categories with same width bars using ggplot2 in R?
- How To Annotate Bars in Bar Plot with Matplotlib in Python?
- How to create histogram like plot with different color of bars in R?

Advertisements