- 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 varying width bar chart using barplot function in R?
The barplot function create the bars of equal width but if we have equal or unequal width values for each bar then we can use width within the barplot function. Thus, the newly generated barplot will have different width of the bars. For example, if we the width are defined for four categories as 0.25 each then each bar will be of equal width and if they vary as 0.30, 0.40, 0.20, 0.45 then the width of the bars will be different based on these widths.
Consider the below vector x and the corresponding width vector −
x<-c(5,7,3,8,2) width<-c(0.2,0.34,0.5,0.4,0.6)
Creating the barplot for x by defining width with width vector −
Example
barplot(x,width)
Output
Example
y<-c(1,4,3,5,8,6,2) width<-c(0.5,0.8,0.3,0.45,0.6,0.4,0.5) barplot(y,width)
Output
- Related Articles
- How to create a horizontal bar plot using barplot function in R?
- How to create stacked barplot using barplot function with each bar having unique color in R?
- How to create stacked barplot using barplot function in R?
- How to create multiple bar plots for varying categories with same width bars using ggplot2 in R?
- How to create a line chart in R using plot function with larger width?
- How to create a bar chart using plotly in R?
- How to create stacked bar chart using ggvis in R?
- How to create bar chart using ggplot2 with chart sub-title in R?
- How to create horizontal stacked bar chart using ggvis in R?
- How to create a line chart using ggplot2 with larger width in R?
- How to create the bar chart with ggplot2 using color brewer in R?
- How to create a bar chart for single vector using ggplot2 in R?
- How to decrease the width of bars for plotly bar chart in R?
- How to create a bar chart using JavaFX?
- How to create plotly bar chart with negative values in R?

Advertisements