Overlapping bar charts in R.

Sergey Ulitenok
2 min readAug 5, 2018

--

It turns out that there is no easy way to create the overlapping bar chart using R base graphics. One method to achieve the desired effect is to draw rectangles with different widths. Here is a code:

Using the rect() function, we can instruct R to draw 4 rectangles (1:4) with specific width parameters for each bar (0.9-.1) for “Price” data, and (0.75–0.25) for “Adjusted_price” data that appears inside the the larger bars.

Your X -axis left limit is set to zero because we want to draw our bars from that point. And your X-axis right limit is set to the maximum length of vectors “price” and “adjusted_price.”

So this is one way. Another one is to make two regular barplot charts in R base and adjust widths of the bars using Adobe Illustrator. Here is how:

Create two barplots in R.

Export the chart as a PDF file to Illustrator, and using the direct selection tool, select the light green bars.

Adjust the bar width of the selected bars using Object > Transform > Transform each > Scale > Vertical > desired width. Adjust colors if needed.

--

--