• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Seaborn
  • Matplotlib
  • ggplot2
  • Altair
  • About
    • Privacy Policy
  • Visualizing Activation Functions in Neural Networks
  • Confusion Matrix Calculator
  • Visualizing Dropout Rate in Neural Network
  • Visualizing Loss Functions in Neural Networks
  • Show Search
Hide Search

Lollipop plot with ggplot extension ggalt

datavizpyr · January 4, 2023 ·

Last updated on August 13, 2025

Creating a lollipop plot with ggalt is an excellent way to visualize ranked data with minimal ink usage compared to traditional bar charts. The ggalt package extends ggplot2 functionality with geom_lollipop(), making it easy to create elegant stick-and-circle visualizations that are both space-efficient and visually appealing.

In this comprehensive lollipop plot ggalt tutorial, you’ll learn how to create, customize, and enhance lollipop plots in R using the ggalt extension package. We’ll cover everything from basic syntax to advanced customization options for creating publication-ready visualizations.

What You’ll Learn

  • How to create lollipop plot with ggalt using geom_lollipop()
  • Making horizontal and vertical lollipop charts with proper orientation
  • Adding colors by categorical variables for grouped comparisons
  • Customizing point size, colors, and styling options
  • Best practices for ggalt lollipop plot design and readability

ggalt, R package developed by @hrbrmstr, has a geom for making lollipop called geom_lollipop(). And we will be using geom_lollipop() to make the lollipo plot and customise a bit.

First, let us load the R packages needed including ggalt. We are use ggalt version 0.4.0 here to make the lollipop plot.

library(tidyverse)
library(gapminder)
library(ggalt)
theme_set(theme_bw(16))
packageVersion("ggalt")
## [1] '0.4.0'

Data preparation for lollipop plot

We will be using a part of gapminder data and make the lollipop plot for the mean life expectancy. values for randomly selected countries from two continents, Africa and Americas.

Let us get the data for making the lollipop chart.

set.seed(2022)
df <- gapminder %>% 
  filter(continent %in% c("Africa", "Americas")) %>%
  group_by(country, continent) %>% 
  summarize(mean_lifeExp = mean(lifeExp)) %>%
  ungroup() %>%
  slice_sample(n =25) 

Our data looks like this with three columns one for country, continent and average life expectancy.

df %>% head()
## # A tibble: 6 × 3
##   country      continent mean_lifeExp
##   <fct>        <fct>            <dbl>
## 1 Namibia      Africa            53.5
## 2 Panama       Americas          67.8
## 3 Venezuela    Americas          66.6
## 4 Tanzania     Africa            47.9
## 5 Botswana     Africa            54.6
## 6 Sierra Leone Africa            36.8

Lollipop plot with geom_lollipop() in ggalt

Now we are ready to make the lollipop plot, a stick with a circle at the end of a stick.

Here we use horizontal=TRUE as argument geom_lollipop() to make the horizontal lollipop chart with country on y axis and mean life expectancy on x axis.

df %>%
  ggplot(aes(y=reorder(country, mean_lifeExp),
             x= mean_lifeExp))+
  geom_lollipop(horizontal=TRUE)+
  labs(y=NULL)
ggsave("lollipop_plot_with_ggalt_geom_lollipop.png")
How to make lollipop plot in R with ggplot
How to make lollipop chart in R with ggplot

Add colors by a variable to Lollipop plot

We can add color to the lollipop chart based. on the value of another variable using color argument to ggplot2’s aes() function.

df  %>%
  ggplot(aes(y=reorder(country, mean_lifeExp),
             x= mean_lifeExp,
             color=continent))+
  geom_lollipop(horizontal=TRUE)+
  labs(y=NULL)+
  theme(legend.position = "top")
ggsave("add_color_lollipop_plot_with_ggalt_geom_lollipop.png")
Add color to lollipop plot
Add color to lollipop plot

Customizing lollipop plot with ggalt

We can also further customize the lollipop plot based on our need. In the example below, we increase the size of circle at the end of stick by using point.size argument to geom_lollipop() function.

df  %>%
  ggplot(aes(y=reorder(country, mean_lifeExp),
             x= mean_lifeExp,
             color=continent))+
  geom_lollipop(point.size=2, 
                horizontal=TRUE)+
  labs(y=NULL)+
  theme(legend.position = "top")
ggsave("customizing_lollipop_plot_with_ggalt_geom_lollipop.png")
Customizing lollipop. plot with geom_lollipop() in ggalt
Customizing lollipop. plot with geom_lollipop() in ggalt

Explore the Complete ggplot2 Guide

35+ tutorials with code: scatterplots, boxplots, themes, annotations, facets, and more—tested and beginner-friendly.

Visit the ggplot2 Hub → No fluff—just code and visuals.

Related posts:

How to add colors to axis tick labels using ggtext?How to Add Colors to Axis Tick Label in ggplot2 Customising Histogram plotting functionHow to write a function make histograms with ggplot How to Increase Color Legend's Point Size in ggplot2How to Increase Legend Key Size in ggplot2 How to reverse legend key order in ggplot2How to reverse legend key order in ggplot2

Filed Under: ggplot2, R, Uncategorized Tagged With: geom_lollipop() ggalt, lollipop plot in R

Primary Sidebar

Python & R Viz Hubs

  • Seaborn Guide & Cookbook
  • ggplot2 Guide & Cookbook
  • Matplotlib Guide & Cookbook
  • Confusion Matrix Calculator
  • Visualizing Activation Functions
  • Visualizing Dropout
  • Visualizing Loss Functions

Buy Me a Coffee

Copyright © 2026 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version