[Solved] R script : add a padding to the ymax of the plot with ggplot2


No code to generate your sample data was provided, so I used the code @akrun had used previously: y3 <- matrix(rnorm(5000), ncol = 5)

library(tidyverse)
as.data.frame(y3) %>%
    mutate(row = row_number()) %>%     # add row to simplify next step
    pivot_longer(-row) %>%             # reshape long
    ggplot(aes(value, color = name)) + # map x to value, color to name
    geom_density()

enter image description here

9

solved R script : add a padding to the ymax of the plot with ggplot2