- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 barplot with one of the bars having different color in R?
A bar plot represents discrete data and the bars in the bar plot are usually of same color but we might want to highlight a particular bar based on the characteristics of the data or the objective of the analysis project. For example, if a particular bar represents highly severe situation or highly unimportant situation then we can change the color that particular bar so that people can easily point out that bar.
Consider the below data frame −
x<-c("X1","X2","X3","X4") freq<-c(56,53,55,57) df<-data.frame(x,freq) df
x freq 1 X1 56 2 X2 53 3 X3 55 4 X4 57
Loading ggplot2 package and creating bar plot with green color for bar showing 57 −
library(ggplot2) ggplot(df,aes(x,freq,fill=x))+geom_bar(stat="identity")+ scale_fill_manual(values=c("blue","blue","blue","green"))
Creating bar plot with blue color for bar showing 57 −
- How to change the color of bars in base R barplot?
- How to create stacked barplot using barplot function with each bar having unique color in R?
- How to create histogram like plot with different color of bars in R?
- How to align the bars of a barplot with the X-axis using ggplot2 in R?
- How to change the space between bars in a barplot in R?
- How to create a circle with different color border in R?
- Fill bars in a base R barplot with colors based on frequency.
- How to create stacked barplot using barplot function in R?
- How to create boxplot of vectors having different lengths in R?
- How to display zero frequency for bars in base R barplot?
- How to create a point chart in R with alternative points having different shape?
- How to create a bar plot in R with label of bars on top of the bars using ggplot2?
- How to create a horizontal line in ggplot2 graph with different color in R?
- How to create a wide vertical line using ggplot2 with different color in R?
- How to create a histogram with dots instead of bars in base R?