#источник: https://t.me/rstudioprogr
library(ggplot2)
library(gridExtra)
library(utils)
library(ggridges)
library(viridis)
## Загрузка требуемого пакета: viridisLite
gapminder <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv")
str(gapminder)
## 'data.frame':    1704 obs. of  6 variables:
##  $ country  : chr  "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
##  $ year     : int  1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ...
##  $ pop      : num  8425333 9240934 10267083 11537966 13079460 ...
##  $ continent: chr  "Asia" "Asia" "Asia" "Asia" ...
##  $ lifeExp  : num  28.8 30.3 32 34 36.1 ...
##  $ gdpPercap: num  779 821 853 836 740 ...
ggplot(data = gapminder, aes(x = lifeExp, y = continent, fill = ..x..)) +
  geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
  labs(title = 'Ожидаемая продолжительность жизни по континентам') + ylab("") +
  theme(legend.position="none", panel.spacing = unit(0.1, "lines"),
    strip.text.x = element_text(size = 8)) + scale_fill_viridis(name = "Величина", option = "A") + theme_bw()
## Warning: The dot-dot notation (`..x..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(x)` instead.
## Picking joint bandwidth of 2.23