Home > Software engineering >  change line color in ggridges
change line color in ggridges

Time:04-13

How to change the line color or shape in a ggridge density plot?

ggplot(iris, aes(x = Sepal.Length, y = Species))  
  geom_density_ridges2()  
  scale_y_discrete(expand = c(0.01, 0))  
  scale_x_continuous(expand = c(0.01, 0))  
  theme_ridges()

enter image description here

CodePudding user response:

I am not sure what you exactly want, but change the color of your lines can be done by using color in your geom_density_ridges2 function like this:

library(tidyverse)
library(ggridges)
ggplot(iris, aes(x = Sepal.Length, y = Species))  
  geom_density_ridges2(color = "red")  
  scale_y_discrete(expand = c(0.01, 0))  
  scale_x_continuous(expand = c(0.01, 0))  
  theme_ridges()

Output:

enter image description here

As you can see, the color of the lines is changed to red.

  • Related