library(ggplot2)
## Warning: пакет 'ggplot2' был собран под R версии 4.3.3
library(ggpubr)
library(viridis)
## Загрузка требуемого пакета: viridisLite
library(ggpmisc)
## Warning: пакет 'ggpmisc' был собран под R версии 4.3.3
## Загрузка требуемого пакета: ggpp
## Warning: пакет 'ggpp' был собран под R версии 4.3.3
## Registered S3 methods overwritten by 'ggpp':
##   method                  from   
##   heightDetails.titleGrob ggplot2
##   widthDetails.titleGrob  ggplot2
## 
## Присоединяю пакет: 'ggpp'
## Следующий объект скрыт от 'package:ggplot2':
## 
##     annotate
## Warning in .recacheSubclasses(def@className, def, env): неопределенный подкласс
## "ndiMatrix" класса ""replValueSp""; определение не обновлено
## Registered S3 method overwritten by 'ggpmisc':
##   method                  from   
##   as.character.polynomial polynom
#Source: https://t.me/rstudioprogr

gapminder <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv")
head(gapminder)
##       country year      pop continent lifeExp gdpPercap
## 1 Afghanistan 1952  8425333      Asia  28.801  779.4453
## 2 Afghanistan 1957  9240934      Asia  30.332  820.8530
## 3 Afghanistan 1962 10267083      Asia  31.997  853.1007
## 4 Afghanistan 1967 11537966      Asia  34.020  836.1971
## 5 Afghanistan 1972 13079460      Asia  36.088  739.9811
## 6 Afghanistan 1977 14880372      Asia  38.438  786.1134
formula <- y ~ x
ggplot(data = gapminder, aes(x = lifeExp, y = gdpPercap)) + geom_point(aes(color = continent), size = 3, alpha = 0.6) + 
  scale_fill_manual(values = c("darkblue", "slateblue", "purple1", "purple4", "blue2"))+ 
  scale_color_manual(values = c("darkblue", "slateblue", "purple1", "purple4", "blue2"))+
  stat_smooth(aes(color = continent, fill = continent), method = "lm") + 
  stat_cor(aes(color = continent), label.y = 115000) + 
  stat_poly_eq(aes(color = continent, label = ..eq.label..), 
               formula = formula, label.y = 4.2, parse = TRUE, 
               label.x = "left") + facet_wrap(~continent, ncol = 5) + theme_classic() + 
  ylab("ВВП на душу населения") + xlab("Ожидаемая продолжительность жизни") + theme(legend.position = "none")
## Warning: The dot-dot notation (`..eq.label..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(eq.label)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'
## Warning: The `scale_name` argument of `continuous_scale()` is deprecated as of ggplot2
## 3.5.0.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `trans` argument of `continuous_scale()` is deprecated as of ggplot2 3.5.0.
## ℹ Please use the `transform` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.