library(ggplot2)
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::select(year, continent, lifeExp) %>% group_by(year, continent) %>%
  dplyr::summarise(value = mean(lifeExp), sd = sd(lifeExp)/sqrt(n())) %>% filter(continent == "Africa")
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
#построим интвервал в 2 сигмы

ggplot(gapminder1) +
  geom_bar(aes(x = year, y = value), stat="identity", alpha = 0.8, fill = "lightblue") +
  geom_errorbar(aes(x = year, y = value, ymin = value - 2*sd, ymax = value + 2*sd), 
                width = 0.4, colour = "orange", alpha = 0.9, size = 0.8) + theme_minimal() + ggtitle("Life Expectancy in Africa from 1952 to 2007", subtitle = "Dataset: gapminder") + labs(y = "Life Expectancy", x = "")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.