wilkelab/ggridges

Missing smoothing bandwidth parameter

AndreyAkinshin opened this issue · 0 comments

Functions like density and geom_density have the bw parameter which defines the smoothing bandwidth to be used. By default, nrd0 is used which is fine for normal distributions, but it's not optimal for multimodal distributions. Let's say we have the following data frame:

df <- data.frame(x = c(
  rnorm(100),
  rnorm(100, 10),
  rnorm(100, 20),
  rnorm(100, 30),
  rnorm(100, 40))
)

That's how the density plot looks like with the default bandwidth:

ggplot(df, aes(x = x)) + geom_density()

plot1
And that's how the same density plot looks like with the Sheather & Jones bandwidth:

ggplot(df, aes(x = x)) + geom_density(bw = "SJ")

plot2

Currently, ggridges supports only the default bandwidth:

ggplot(df, aes(x = x, y = 1)) + geom_density_ridges()

plot3

It would be nice to introduce the bw parameter in geom_density_ridges and geom_density_ridges2.