

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 manually set the color of each bar in base R bar plot?
To manually set the color of each bar in base R bar plot, we can follow the below steps −
- First of all, create a vector.
- Then create the bar plot with col argument.
Example 1
Create the vector
Let’s create a vector as shown below −
x<-sample(1:100,3) x
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
[1] 44 27 8
Create the bar plot with col argument
Using col argument to set the color of each bar manually −
Live Demo
x<-sample(1:100,3) barplot(x,col=c("red","green","blue"))
Output
Example 2
Create the vector
Let’s create a vector as shown below −
y<-rpois(3,10) y
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
[1] 13 14 6
Create the bar plot with col argument
Using col argument to set the color of each bar manually −
y<-rpois(3,10) barplot(y,col=c("grey","yellow","pink"))
Output
- Related Questions & Answers
- How to create horizontal lines for each bar in a bar plot of base R?
- How to create empty bar plot in base R?
- How to display x-bar in base R plot?
- How to set the plot area to assign the plots manually in base R?
- How to create stacked bar plot in which each bar sum to 1 or 100% in R?
- How to change the color of bars of a bar plot using ggplot2 in R?
- Create bar plot for grouped data of two columns in base R.
- How to set the alignment of labels in horizontal bar plot to left in R?
- How to highlight a bar in base R histogram?
- How to create bar plot in base R with different limits for Y-axis?
- How to change the axis color in base R plot?
- How to change the background color of base R plot region?
- How to manually set the colors of density plot for categories in R?
- How to change the background color of legend in base R plot?
- How to create a bar plot in R filled with color palette in RColorBrewer package?
Advertisements