rggplot2ggridges

how to increase white space at top of panel when using geom_density_ridges()


When I make a plot using geom_density_ridges() the top most plot touches the top of the panel. How do I create a little white space there for aesthetic purposes?

library(ggplot2)
library(ggridges)

ggplot(iris, aes(x = Sepal.Length, y = Species)) + 
   geom_density_ridges()

enter image description here


Solution

  • This could be achieved by increasing the expansion of the y scale via the expand argument of scale_y_discrete:

    library(ggplot2)
    library(ggridges)
    
    ggplot(iris, aes(x = Sepal.Length, y = Species)) + 
      geom_density_ridges() +
      scale_y_discrete(expand = expansion(add = c(.3, 1.4)))
    #> Picking joint bandwidth of 0.181