#источник: https://t.me/rstudioprogr
library(AER)
## Загрузка требуемого пакета: car
## Загрузка требуемого пакета: carData
## Загрузка требуемого пакета: lmtest
## Загрузка требуемого пакета: zoo
## 
## Присоединяю пакет: 'zoo'
## Следующие объекты скрыты от 'package:base':
## 
##     as.Date, as.Date.numeric
## Загрузка требуемого пакета: sandwich
## Загрузка требуемого пакета: survival
library(ggplot2)
library(gridExtra)

data("CigarettesSW")
head(CigarettesSW)
##   state year   cpi population    packs    income  tax     price     taxs
## 1    AL 1985 1.076    3973000 116.4863  46014968 32.5 102.18167 33.34834
## 2    AR 1985 1.076    2327000 128.5346  26210736 37.0 101.47500 37.00000
## 3    AZ 1985 1.076    3184000 104.5226  43956936 31.0 108.57875 36.17042
## 4    CA 1985 1.076   26444000 100.3630 447102816 26.0 107.83734 32.10400
## 5    CO 1985 1.076    3209000 112.9635  49466672 31.0  94.26666 31.00000
## 6    CT 1985 1.076    3201000 109.2784  60063368 42.0 128.02499 51.48333
str(CigarettesSW)
## 'data.frame':    96 obs. of  9 variables:
##  $ state     : Factor w/ 48 levels "AL","AR","AZ",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ year      : Factor w/ 2 levels "1985","1995": 1 1 1 1 1 1 1 1 1 1 ...
##  $ cpi       : num  1.08 1.08 1.08 1.08 1.08 ...
##  $ population: num  3973000 2327000 3184000 26444000 3209000 ...
##  $ packs     : num  116 129 105 100 113 ...
##  $ income    : num  4.60e+07 2.62e+07 4.40e+07 4.47e+08 4.95e+07 ...
##  $ tax       : num  32.5 37 31 26 31 ...
##  $ price     : num  102.2 101.5 108.6 107.8 94.3 ...
##  $ taxs      : num  33.3 37 36.2 32.1 31 ...
ggplot(data = CigarettesSW, aes(x = population, fill = year)) + geom_density() + theme_bw()

g1 <- ggplot(data = CigarettesSW, aes(x = population, fill = year)) + geom_density(alpha = 0.5) + theme_bw() + ggtitle("Пример №1") + theme(legend.position = "bottom")

g2 <- ggplot(data = CigarettesSW, aes(x = population, fill = year)) + geom_density(alpha = 0.5) + theme_bw() + ggtitle("Пример №2") + scale_fill_manual(values = c("lightblue", "darkblue"))+ theme(legend.position = "bottom")
g3 <- ggplot(data = CigarettesSW, aes(x = population, fill = year)) + geom_density(alpha = 0.5) + theme_bw() + ggtitle("Пример №3 - сайт romanuke") + scale_fill_manual(values = c("#a30078", "#b7dafa"))+ theme(legend.position = "bottom")

grid.arrange(g1, g2, g3, ncol = 3)