R

ridgeline plot

이부일 2020. 2. 23. 17:51

# ridgeline 그래프는 시간의 흐름에 따른 분포의 추세를 보여줄 때 유용한 그래프이다.

install.packages("tidyverse")
install.packages("gapminder")
install.packages("ggridges")
library(tidyverse)
library(gapminder)
library(ggridges)

 

 

# 연도별 기대수명의 현황
gapminder %>%
     ggplot2::ggplot(aes(x = lifeExp, y = as.factor(year), fill = as.factor(year))) +
     ggridges::geom_density_ridges(alpha = 0.5) +
     ggplot2::theme_classic() +
     ggplot2::labs(title = "Ridge Line Graph",
                        x    = "Life Expection",
                        y    = "Year") +
     ggplot2::theme(plot.title  = element_text(size = 15, face = "bold", hjust = 0.5),
                          axis.title.x = element_text(face = "bold"),
                          axis.title.y = element_text(face = "bold")) +
     ggplot2::guides(fill = guide_legend(title = "Year"))