• 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
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How to make rain cloud plots with ggdist

datavizpyr · August 3, 2022 ·

In this tutorial, we will learn how to make raincloud plots with the R package ggdist. In an earlier post, we learned how to make rain cloud plots with half violinplot, kind of from scratch. However, ggdist, an R package “that provides a flexible set of ggplot2 geoms and stats designed especially for visualizing distributions and uncertainty”, makes it easy to create rain cloud plots using special geoms.

We can use ggdist’s geom_dotsinterval() / stat_dotsinterval() functions to make rain cloud plots, which is a combination of half-eyes or half violin plot, boxplot and beeswarm/dotplots.

Let us load the packages needed to make rain cloud plot.

library(tidyverse)
library(palmerpenguins)
library(ggdist)
theme_set(theme_bw(16)
packageVersion("ggdist")
## [1] '3.2.0'

Half eye or Half Violin Plot with ggdist

We will build rain cloud plot step by step using ggdist’s function. First, let us make density/ridge/half-eye/half-violin plot. With ggdist, we can make half violin plot (or half eye) using stat_slab() function.

penguins %>%
  ggplot(aes(x=flipper_length_mm, y=species, fill=species))+
  stat_slab(aes(thickness = stat(pdf*n)),
                scale = 0.7) 
ggsave("ggdist_raincloud_plot.png")
Ridge plot or half violin plot with ggdist
Ridge plot or half violin plot with ggdist

Simple rain cloud plot with ggdist

By adding “stat_dotsinterval” function we can make rain cloud plot. Here with “side=bottom” argument makes the dot plots to be at the bottom of the density plot to make it look like rain cloud plot.

penguins %>%
  ggplot(aes(x=flipper_length_mm, y=species, fill=species))+
  stat_slab(aes(thickness = stat(pdf*n)), 
                scale = 0.7) +
  stat_dotsinterval(side = "bottom", 
                    scale = 0.7, 
                    slab_size = NA) 
ggsave("ggdist_raincloud_plot_with_summary_interval.png")
Rain cloud plot: ggdist default
Rain cloud plot: ggdist default

Simple customizations to rain cloud plot

The above rain cloud plot is default one. We can improve the plot simply changing the color palette used and removing the legend as it is redundant. And also add a title to the rain cloud plot

penguins %>%
  ggplot(aes(x=flipper_length_mm, y=species, fill=species))+
  stat_slab(aes(thickness = stat(pdf*n)), 
                scale = 0.7) +
  stat_dotsinterval(side = "bottom",
                    scale = 0.7,
                    slab_size = NA) + 
  scale_fill_brewer(palette = "Set2") +
  theme(legend.position = "none")+
  labs(title="Raincloud plot with ggdist")
ggsave("ggdist_raincloud_plot_with_datapoints_as_drops.png")
Rain cloud plots with ggdist
Rain cloud plots with ggdist

Related posts:

Customizing Mean mark to boxplot with ggplot2How To Show Mean Value in Boxplots with ggplot2? Scatterplot with marginal multi-histogram with ggExtraHow To Make Scatterplot with Marginal Histograms in R? ggforce geom_circle(): Annotate with a circleHow To Annotate a Plot with Circle in R Default ThumbnailHow to Make Axis Text Bold in ggplot2

Filed Under: ggdist, ggplot2, R Tagged With: ggdist ggplot2 extension package, rain cloud plots with ggdist

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

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

Go to mobile version