Skip to main content

Raincloud plot

A raincloud plot overlays three complementary views of each group on one shared axis:

LayerWhat it is
CloudA half-violin (KDE) — the distribution's shape
BoxA narrow box and whisker — the five-number summary
RainJittered raw points — every individual observation

Together they avoid the box plot's information loss (the shape is hidden), the strip plot's clutter (the structure is obscured), and the violin's anonymity (the sample size is invisible).

SELECT kuva_render(to_json({
'title': 'Expression by treatment',
'x_axis': {'name': 'group'},
'y_axis': {'name': 'expression'},
'series': [{
'type': 'raincloud',
'groups': groups
}]
})) AS chart
FROM (
SELECT list({'label': g, 'values': vals} ORDER BY g) AS groups
FROM (
SELECT "group" AS g, list(expression) AS vals
FROM read_csv_auto('{{DFK_BASE_URL}}data/samples.tsv')
GROUP BY "group"
)
);

Several groups are coloured from the palette automatically; a single group uses the uniform color.

Toggling the layers​

Each of the three can be turned off on its own, which is how you get the simpler chart when all three are not needed:

FieldEffect
show_cloud: falseBox + rain only — no KDE
show_box: falseCloud + rain only — no summary
show_rain: falseCloud + box only — no raw points
SELECT kuva_render(to_json({
'title': 'Cloud + box only',
'x_axis': {'name': 'group'},
'y_axis': {'name': 'expression'},
'series': [{
'type': 'raincloud',
'groups': groups,
'show_rain': false
}]
})) AS chart
FROM (
SELECT list({'label': g, 'values': vals} ORDER BY g) AS groups
FROM (
SELECT "group" AS g, list(expression) AS vals
FROM read_csv_auto('{{DFK_BASE_URL}}data/samples.tsv')
GROUP BY "group"
)
);

KDE bandwidth​

The cloud is a kernel density estimate, so it has the same smoothing knob as everywhere else — chosen by Silverman's rule unless you say otherwise.

bandwidth_scale multiplies the automatic choice instead of replacing it (adjust in ggplot2): below 1 is sharper and more data-sensitive, above 1 is smoother.

SELECT kuva_render(to_json({
'title': 'Sharper clouds',
'x_axis': {'name': 'group'},
'y_axis': {'name': 'expression'},
'series': [{
'type': 'raincloud',
'groups': groups,
'bandwidth_scale': 0.5
}]
})) AS chart
FROM (
SELECT list({'label': g, 'values': vals} ORDER BY g) AS groups
FROM (
SELECT "group" AS g, list(expression) AS vals
FROM read_csv_auto('{{DFK_BASE_URL}}data/samples.tsv')
GROUP BY "group"
)
);

bandwidth sets an exact value, overriding both Silverman's rule and the scale, and kde_samples sets how many points the curve is evaluated at (default 200).

Flip direction​

The cloud sits to the right of centre and the rain to the left. flip swaps them — useful when you want the density on the same side as another chart's, or just to match a figure style.

SELECT kuva_render(to_json({
'title': 'Flipped',
'x_axis': {'name': 'group'},
'y_axis': {'name': 'expression'},
'series': [{
'type': 'raincloud',
'groups': groups,
'flip': true
}]
})) AS chart
FROM (
SELECT list({'label': g, 'values': vals} ORDER BY g) AS groups
FROM (
SELECT "group" AS g, list(expression) AS vals
FROM read_csv_auto('{{DFK_BASE_URL}}data/samples.tsv')
GROUP BY "group"
)
);

Per-group colours​

colors assigns fill colours to groups by position; group, cloud, box and rain all take the same one.

SELECT kuva_render(to_json({
'title': 'Per-group colours',
'x_axis': {'name': 'group'},
'y_axis': {'name': 'expression'},
'series': [{
'type': 'raincloud',
'groups': groups,
'colors': ['#4878d0', '#ee854a', '#6acc65', '#d65db1', '#8c6bb1']
}]
})) AS chart
FROM (
SELECT list({'label': g, 'values': vals} ORDER BY g) AS groups
FROM (
SELECT "group" AS g, list(expression) AS vals
FROM read_csv_auto('{{DFK_BASE_URL}}data/samples.tsv')
GROUP BY "group"
)
);

Legend​

A legend for a raincloud shows one entry per group, labelled from the group labels — so legend just turns it on.

SELECT kuva_render(to_json({
'title': 'With a legend',
'x_axis': {'name': 'group'},
'y_axis': {'name': 'expression'},
'legend': {'position': 'outside_right_top'},
'series': [{
'type': 'raincloud',
'groups': groups,
'legend': 'group'
}]
})) AS chart
FROM (
SELECT list({'label': g, 'values': vals} ORDER BY g) AS groups
FROM (
SELECT "group" AS g, list(expression) AS vals
FROM read_csv_auto('{{DFK_BASE_URL}}data/samples.tsv')
GROUP BY "group"
)
);

Fine-tuning the layout​

Every offset and width is adjustable when the groups crowd each other or look sparse:

FieldDefaultWhat it moves
cloud_width30Maximum pixel half-width of the cloud
cloud_offset0.15Cloud centre, away from the group centre
box_width0.08Box half-width, as a fraction of the slot
rain_offset0.20Rain centre, away from the group centre
rain_size3Rain point radius in pixels
rain_jitter0.05Horizontal spread of the rain
cloud_alpha0.7Cloud fill opacity
rain_alpha0.7Rain point opacity
seed42RNG seed for the jitter, so output is reproducible
SELECT kuva_render(to_json({
'title': 'Wider clouds, tighter rain',
'x_axis': {'name': 'group'},
'y_axis': {'name': 'expression'},
'series': [{
'type': 'raincloud',
'groups': groups,
'cloud_width': 45,
'cloud_offset': 0.20,
'rain_offset': 0.25,
'rain_size': 2.5,
'rain_jitter': 0.04,
'cloud_alpha': 0.6,
'rain_alpha': 0.5
}]
})) AS chart
FROM (
SELECT list({'label': g, 'values': vals} ORDER BY g) AS groups
FROM (
SELECT "group" AS g, list(expression) AS vals
FROM read_csv_auto('{{DFK_BASE_URL}}data/samples.tsv')
GROUP BY "group"
)
);

Horizontal mode​

horizontal rotates the chart so the categories run down the y axis — the better layout for long labels.

SELECT kuva_render(to_json({
'title': 'Horizontal raincloud',
'x_axis': {'name': 'expression'},
'y_axis': {'name': 'group'},
'series': [{
'type': 'raincloud',
'groups': groups,
'horizontal': true
}]
})) AS chart
FROM (
SELECT list({'label': g, 'values': vals} ORDER BY g) AS groups
FROM (
SELECT "group" AS g, list(expression) AS vals
FROM read_csv_auto('{{DFK_BASE_URL}}data/samples.tsv')
GROUP BY "group"
)
);

Fields​

FieldTypeWhat it sets
groupsgroup[]Required. One raincloud per group, each {label, values, color?}.
colorsstring[]Per-group colours, matched to groups by position.
show_cloudbooleanDraw the half-violin (default true).
cloud_widthnumberMaximum pixel half-width of the cloud (default 30).
cloud_offsetnumberOffset of the cloud centre from the group centre (default 0.15).
cloud_alphanumberCloud fill opacity (default 0.7).
bandwidthnumberExplicit KDE bandwidth; overrides Silverman and the scale.
bandwidth_scalenumberMultiplier on the automatic bandwidth (default 1).
kde_samplesintegerKDE evaluation points (default 200).
show_boxbooleanDraw the box and whisker (default true).
box_widthnumberBox half-width as a fraction of the slot (default 0.08).
show_rainbooleanDraw the jittered points (default true).
rain_sizenumberRain point radius in pixels (default 3).
rain_jitternumberHorizontal jitter spread (default 0.05).
rain_alphanumberRain point opacity (default 0.7).
rain_offsetnumberOffset of the rain centre from the group centre (default 0.20).
flipbooleanSwap cloud and rain sides (default false).
seedintegerRNG seed for the jitter (default 42).
horizontalbooleanRotate: categories on the y axis, values on the x axis.

color and legend come from series & shared fields; legend turns on one entry per group.

Notes​

  • Every group needs at least one value; an empty groups list is an error.
  • bandwidth beats bandwidth_scale, which beats Silverman's rule.
  • show_* flags are what let one chart double as a violin, a box plot or a strip plot.
  • The three layers share the y axis, so they are directly comparable — that is the whole point.

See also​