How to Make Grouped Bar Plot with Same Bar Width in R
In this article, we will discuss How to Make Grouped Bar Plot with the Same Bar Width in R Programming Language.
Method 1 : Using position_dodge2(preserve = “single”)
The geom_col() method can be used to add positions to the graph. Dodging preserves the vertical position of an geom while adjusting the horizontal position. The position_dodge2 method is used to work with bars and rectangle.
position_dodge2(width = NULL, preserve = c("total", "single"))
- width – Dodging width, when different to the width of the individual elements.
- preserve – Indicator of whether of not dodging should preserve the total width of all elements at a position or a single element.
Method 2 : Using barplot method
The barplot() method in base R is used to construct successive bar plots from the given input table or matrix. The widths of the bars are equal unless explicitly specified using the width parameter.
barplot(data, xlab, ylab)
- data – The input data frame
- xlab – The label for x axis
- ylab – The label for y axis