- 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

# Fill bars in a base R barplot with colors based on frequency.

Suppose we have a vector that contains only frequencies and we want to create a bar chart in base R using these frequencies with color of bars based on frequencies, therefore, we can use barplot function and providing the color of the bars with as shown in the below Examples

The function is as follows −

heat.colors function

## Example 1

To fill the bars in a base R barplot with colours based on frequency, use the command given below −

Frequency_1<-c(2,4,8,3,10,1) barplot(Frequency_1,col=heat.colors(max(Frequency_1))[Frequency_1])

## Output

If you execute the above given snippet, it generates the following Output −

## Example 2

To fill the bars in a base R barplot with colours based on frequency, use the command given below −

Frequency_2<-c(25,31,28,21,15,45) barplot(Frequency_2,col=heat.colors(max(Frequency_2))[Frequency_2])

## Output

If you execute the above given snippet, it generates the following Output −

- Related Questions & Answers
- How to fill bars of a bar plot created using ggplot2 with colors based on frequency?
- How to display zero frequency for bars in base R barplot?
- How to fill histogram bars using ggplot2 in R with different colors?
- How to change the color of bars in base R barplot?
- How to change the space between bars in a barplot in R?
- How to display legend in base R with different colors?
- How to create a barplot with one of the bars having different color in R?
- How to align the bars of a barplot with the X-axis using ggplot2 in R?
- How to create a histogram with dots instead of bars in base R?
- How to create side by side barplot in base R?
- How to find the frequency with subsetting in base R?
- How to display negative labels below bars in barplot using ggplot2 in R?
- How to create a barplot with gaps on Y-axis scale in R?
- How to fill the outliers with different color in base R boxplot?
- Setting different error bar colors in barplot in Matplotlib

Advertisements