- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 histogram like plot with different color of bars in R?
To create histogram like plot with different color of bars, we can use col argument and provide the range up to the number of bars we expect in the histogram like plot.
For example, if we have a vector of length 10 called X then we can create histogram like plot of X with different color of bars using the command given below −
plot(X,type="h",col=1:10,lwd=5)
Check out the below example to understand how it works.
Example
To create histogram like plot with different color of bars, use the following command −
x<-rpois(5,2) plot(x,type="h")
Output
If you execute the above given command, it generates the following output −
To create histogram like plot with different color of bars, add the following code to the above snippet −
x<-rpois(5,2) plot(x,type="h",col=1:5)
Output
If you execute all the above given snippets as a single program, it generates the following output −
To create histogram like plot with different color of bars, add the following code to the above snippet −
x<-rpois(5,2) plot(x,type="h",col=1:5,lwd=5)
Output
If you execute all the above given snippets as a single program, it generates the following output −
- Related Articles
- How to create a barplot with one of the bars having different color in R?
- How to fill histogram bars using ggplot2 in R with different colors?
- How to create a histogram with dots instead of bars in base R?
- Change the outline color for histogram bars using ggplot2 in R.
- How to create a bar plot in R with label of bars on top of the bars using ggplot2?
- How to create a bar plot with bars for missing values in R?
- How to create plot in R with different shape of points?
- How to change the color of bars of a bar plot using ggplot2 in R?
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- How to create a circle with different color border in R?
- How to remove border of bars from histogram in base R?
- How to create bar plot of means with error bars of standard deviations using ggplot2 in R?
- How to specify different colors for different bars in a Python matplotlib histogram?
- How to create a plot in R with a different plot window size using plot function?
- How to create histogram with relative frequency in R?
