1

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

Joe
  • 3,217
  • 3
  • 21
  • 37

1 Answers1

2

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

stefan
  • 90,330
  • 6
  • 25
  • 51