- 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 display NA frequency for a ggplot2 graph using color brewer in R?
To display NA frequency for a ggplot2 graph using color brewer in R, we can follow the below steps −
- First of all, create a data frame.
- Then, create the chart with default colors.
- After that, use scale_colour_brewer function to create the bar chart and set the color of NA values bar with na.value.
Create the data frame
Let's create a data frame as shown below −
Group<-c("A","B","C",NA) Count<-c(24,21,27,25) df<-data.frame(Group,Count) df
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
Group Count 1 A 24 2 B 21 3 C 27 4 <NA> 25
Create the bar chart with default colors
Loading ggplot2 package and creating the bar for the data in df −
Group<-c("A","B","C",NA) Count<-c(24,21,27,25) df<-data.frame(Group,Count) library(ggplot2) ggplot(df,aes(Group,Count,fill=Group))+geom_bar(stat="identity")
Output
Create the bar chart with color brewer and change the color of bar representing NA
Use scale_colour_brewer function of ggplot2 package to create the bar chart and set the color of NA values bar to red with na.value as shown below −
Group<-c("A","B","C",NA) Count<-c(24,21,27,25) df<-data.frame(Group,Count) library(ggplot2) ggplot(df,aes(Group,Count,fill=Group))+geom_bar(stat="identity")+scale_fill_brewer(pa lette="Accent",na.value="red")
Output
- Related Articles
- How to display NA group values in scatterplot created with ggplot2 using color brewer in R?
- How to change the color of points for ggplot2 scatterplot using color brewer in R?
- How to create the bar chart with ggplot2 using color brewer in R?
- How to display tilde ggplot2 graph in R?
- How to display a variable with subscript ggplot2 graph in R?
- Remove grey color from legend display using ggplot2 in R.
- How to display mean line per group in facetted graph using ggplot2 in R?
- How to change the plot border color of a ggplot2 graph in R?
- How to change the color of gridlines of a ggplot2 graph in R?
- How to create a horizontal line in ggplot2 graph with different color in R?
- How to display average line for y variable using ggplot2 in R?
- How to create a horizontal bar graph using ggplot2 in R?
- How to display mean in a histogram using ggplot2 in R?
- R Programming how to display both axes’ labels of a ggplot2 graph in italics?
- How to change the bars color to grey shade of a bar graph created by using ggplot2 in R?

Advertisements