library(ggplot2)
library(gghighlight)
library(RColorBrewer)
library(dplyr)
## 
## Присоединяю пакет: 'dplyr'
## Следующие объекты скрыты от 'package:stats':
## 
##     filter, lag
## Следующие объекты скрыты от 'package:base':
## 
##     intersect, setdiff, setequal, union
gapminder <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv")
gapminder1 <- gapminder %>% dplyr::filter(gapminder$year == 2007)
head(gapminder1)
##       country year      pop continent lifeExp  gdpPercap
## 1 Afghanistan 2007 31889923      Asia  43.828   974.5803
## 2     Albania 2007  3600523    Europe  76.423  5937.0295
## 3     Algeria 2007 33333216    Africa  72.301  6223.3675
## 4      Angola 2007 12420476    Africa  42.731  4797.2313
## 5   Argentina 2007 40301927  Americas  75.320 12779.3796
## 6   Australia 2007 20434176   Oceania  81.235 34435.3674
ggplot(gapminder1, aes(x = lifeExp, fill = continent)) + 
  geom_histogram() + facet_wrap(~ continent) +
  labs(x = "Ожидаемая продолжительность жизни", y = "Частота", title = "Отражение частоты выборки в разрезе подвыборок") +
  theme_minimal() + theme(legend.position = "none") + gghighlight::gghighlight() + scale_fill_brewer(palette = "Blues") + theme_classic()
## label_key: continent
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

#аналогично можно сделать geom_density()
ggplot(gapminder1, aes(x = lifeExp, fill = continent)) + 
  geom_density() + facet_wrap(~ continent) +
  labs(x = "Ожидаемая продолжительность жизни", y = "Частота", title = "Отражение общего распределения выборки в разрезе подвыборок") +
  theme_minimal() + theme(legend.position = "none") + gghighlight::gghighlight() + scale_fill_brewer(palette = "Spectral") + theme_classic()

ggplot(gapminder1, aes(x = gdpPercap, fill = continent)) + 
  geom_histogram() + facet_wrap(~ continent) +
  labs(x = "ВВП на душу населения", y = "Частота", title = "Отражение частоты выборки в разрезе подвыборок") +
  theme_minimal() + theme(legend.position = "none") + gghighlight::gghighlight() + scale_fill_brewer(palette = "Spectral") + theme_classic()
## label_key: continent
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.