- 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 in R filled with color palette in RColorBrewer package?
To create a bar plot in R filled with color palette in RColorBrewer package, we can follow the below steps −
- First of all, create a vector.
- Create the bar plot with color palette in RColorBrewer package.
Example 1
Let’s create a vector as shown below −
x<-sample(1:10,5) x
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
Output
[1] 2 7 3 1 9
Create the bar plot
Using brewer.pal to color the bars in bar plot −
x<-sample(1:10,5) barplot(x,col=brewer.pal(n=5,name="Set3"))
Output
Example 2
Let’s create a vector as shown below −
y<-sample(1:9,5) y
[1] 9 4 3 8 2
Create the bar plot
Using brewer.pal to color the bars in bar plot −
y<-sample(1:9,5) barplot(y,col=brewer.pal(n=5,name="BrBG"))
Output
Example 3
Let’s create a vector as shown below −
z<-rpois(3,10) z
[1] 10 11 5
Create the bar plot
Using brewer.pal to color the bars in bar plot −
z<-rpois(3,10) barplot(z,col=brewer.pal(n=3,name="Dark2"))
Output
- Related Articles
- How to create violin plot for categories with grey color palette using ggplot2 in R?
- How to create a circle filled with a color in R?
- How to create violin plot for categories with grey color palette in reverse order using ggplot2 in R?
- How to create scatterplot for categories with grey color palette using ggplot2 in R?
- How to create boxplot for categories with grey color palette using ggplot2 in R?
- How to create a bar plot with ggplot2 using stat_summary in R?
- How to create line chart for categories with grey color palette using ggplot2 in R?
- How to create a bar plot with bars for missing values in R?
- How to create a bar plot using ggplot2 with one bar having black border in R?
- How to create density plot for categories filled with different colors in R?
- How to create boxplot for categories with grey color palette in reverse order using ggplot2 in R?
- What are the different color palettes we have in RColorBrewer package?
- How to create empty bar plot in base 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?

Advertisements