wilkelab / ggridges

Ridgeline plots in ggplot2
https://wilkelab.org/ggridges
GNU General Public License v2.0
411 stars 31 forks source link

geom_density_ridges Minimum Samples per Group is Not Documented #97

Closed DarioS closed 3 months ago

DarioS commented 3 months ago

?geom_density_ridges does not explicitly state the minimum number of observations per group. It seems to be three.

> ggplot(iris[1:102, ], aes(x = Sepal.Length, y = Species)) + geom_density_ridges() # However, 1:103 is fine.
Picking joint bandwidth of 0.16

image

Why no message or warning but only a blank row? I first noticed this issue from enrichplot when the core gene set size is 2.

> result[, c(1:6, 10:11)] # core gene set has only PLAU and APOE genes in it.
                   ID                     Description setSize enrichmentScore     NES
GO:0030193 GO:0030193 regulation of blood coagulation      10        0.695895 1.60145
GO:0050818 GO:0050818       regulation of coagulation      10        0.695895 1.60145
GO:1900046 GO:1900046        regulation of hemostasis      10        0.695895 1.60145
           pvalue                  leading_edge core_enrichment
GO:0030193  0.027 tags=20%, list=4%, signal=20%       PLAU/APOE
GO:0050818  0.027 tags=20%, list=4%, signal=20%       PLAU/APOE
GO:1900046  0.027 tags=20%, list=4%, signal=20%       PLAU/APOE

image

The original density plot has no issues with two observations: ggplot(diamonds[1:2, ], aes(carat)) + geom_density() is not blank.

clauswilke commented 3 months ago

Honestly, if you have that few observations, you shouldn't make density plots anyways. If you don't have at least 20-50 points density estimates are useless.

DarioS commented 3 months ago

Fair point. enrichplot's ridgeplot should not attempt to plot such scenarios.