- 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 change the color of bars in base R barplot?
To change the color of bars in base R barplot, we can use col argument inside the barplot function.
For example, if we have a vector called V for which we want to create the barplot then we can use the command given below to get the bars in blue color −
barplot(V,col="blue")
Check out the below example to understand how it can be done.
Example
To change the color of bars in base R barplot, use the code given below −
x<-rpois(10,5) x
If you execute the above given code, it generates the following output −
[1] 4 3 2 8 2 8 4 2 3 5
To change the color of bars in base R barplot, add the following code to the above code −
x<-rpois(10,5) barplot(x)
Output
If you execute all the above given snippets as a single program, it generates the following output −
To change the color of bars in base R barplot, add the following code to the above code −
x<-rpois(10,5) barplot(x,col="red")
Output
If you execute all the above given snippets as a single program, it generates the following output −
To change the color of bars in base R barplot, add the following code to the above code −
x<-rpois(10,5) barplot(x,col="blue")
Output
If you execute all the above given snippets as a single program, it generates the following output −
- Related Articles
- How to display zero frequency for bars in base R barplot?
- How to change the space between bars in a barplot in R?
- How to create a barplot with one of the bars having different color in R?
- Fill bars in a base R barplot with colors based on frequency.
- How to change the axis color in base R plot?
- How to change the color of box of boxplot in base R?
- How to change the background color of base R plot region?
- How to change the color of bars of a bar plot using ggplot2 in R?
- How to change the background color of legend in base R plot?
- How to change the color of outliers in base R boxplot?\n
- How to change the axis ticks color in base R plot?
- Change the outline color for histogram bars using ggplot2 in R.
- How to change the border color of box of a base R plot?
- How to align the bars of a barplot with the X-axis using ggplot2 in R?
- How to display negative labels below bars in barplot using ggplot2 in R?
