How to do it...

Visualizing multiple distributions with ridgeplots can be done using the following steps:

  1. Load the libraries:
library(ggplot2)
library(ggridges)
  1. Build a ggplot description:
ggplot(airquality) + aes(Temp, Month, group = Month) + geom_density_ridges()
  1. Explicitly make Month a factor:
ggplot(airquality) + aes(Temp, as.factor(Month) ) + geom_density_ridges()
  1. Color the ridges:
ggplot(airquality) + aes(Temp, Month, group = Month,  fill = ..x..) + 
  geom_density_ridges_gradient() + 
  scale_fill_viridis(option = "C", name = "Temp")
  1. Reshape the dataframe and add facets:
library(tidyr)
airquality %>%
  gather(key = "Measurement", value = "value", Ozone, Solar.R, Wind, Temp ) %>%
  ggplot() + aes(value, Month, group = Month) + 
  geom_density_ridges_gradient() +
  facet_wrap( ~ Measurement, scales = "free")
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.102.6