top of page

How to Create a Lollipop Chart in R with ggplot2

hands typing on keyboard

Overview

A lollipop chart is a type of data visualization that combines elements of a bar chart and a point chart. It consists of a vertical or horizontal line (the "stick") with a dot (the "lollipop") at the end, representing the value associated with each category. This format allows for easy comparison of values across different categories while providing a visually appealing alternative to traditional bar charts.

Example of a Lollipop Chart

example of a lollipop chart

Step-by-step guide

To create a lollipop chart in R with ggplot2…

Load the necessary libraries and dataset as shown below.

loading libraries and data in r session

(Note, I am using the Sample – Superstore dataset)

Using the geom_segment and geom_point functions, I will create a lollipop chart showing the Sales by product Sub-Category using the code below.

code for creating a simple lollipop chart in r

The above code summarizes the Sales by product Sub-Category, before applying the ggplot(), geom_segment() and geom_point() functions to plot the lollipop chart.

Executing the above code plots the view below.

sample lollipop chart

Finally, let’s declutter the view using the classic theme as shown below.

code for decluttering a lollipop chart - using the classic theme

Executing the above code generates a cleaner lollipop chart as shown below.

final view of a lollipop chart in r

Conclusion

Lollipop charts are an effective and visually engaging method for presenting data, particularly when comparing values across categories. They combine elements of scatter plots and bar charts, allowing for a clear representation of numerical data in relation to categorical variables. The versatility of lollipop charts makes them suitable for various applications, from business analytics to scientific research.

Lollipop charts serve as an effective alternative to standard bar charts, particularly in scenarios requiring clarity and visual appeal in data presentation. However, users should consider their potential limitations regarding precision and data suitability.

If you like the work we do and would like to work with us, drop us an email on our contacts page and we’ll reach out!

Thank you for reading!

Original.png

We Support You Deliver Business-Focused Solutions That Enable Data-Driven Decision Making.

  • Tableau profile
  • YouTube
  • White LinkedIn Icon
  • Facebook
  • X

QUICK LINKS

CONTACT US

+254 738 307 495

East Gate Mall, Donholm

3rd Floor Suite No. 3i

Nairobi, Kenya

Join our mailing list

bottom of page