Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading