wilkelab / ggridges

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

Missing smoothing bandwidth parameter #38

Open AndreyAkinshin opened 5 years ago

AndreyAkinshin commented 5 years ago

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.