library(ggplot2)
## Warning: пакет 'ggplot2' был собран под R версии 4.2.1
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")
gapminder %>% filter(pop == max(gapminder$pop))
## country year pop continent lifeExp gdpPercap
## 1 China 2007 1318683096 Asia 72.961 4959.115
g1 <- gapminder %>% filter(country %in% c("Brazil", "China")) %>% ggplot(aes(x = year, y = pop, color = country)) + geom_line(size = 2) + theme_bw() + scale_color_manual(values = c("darkblue", "lightblue")) + ggtitle("График №1. Шкала по умолчанию") + theme(legend.position = "bottom")
g1

g2 <- gapminder %>% filter(country %in% c("Brazil", "China")) %>% ggplot(aes(x = year, y = pop, color = country)) + geom_line(size = 2) + theme_bw() + scale_color_manual(values = c("darkblue", "lightblue")) + ggtitle("График №2. Соответствующая шкала") + scale_y_continuous(labels = scales::comma) + theme(legend.position = "bottom")
g2

g3 <- gapminder %>% filter(country %in% c("Brazil", "China")) %>% ggplot(aes(x = year, y = gdpPercap, color = country)) + geom_line(size = 2) + theme_bw() + scale_color_manual(values = c("darkblue", "lightblue")) + ggtitle("График №3. Шкала с валютой") + scale_y_continuous(labels=scales::dollar_format())+ theme(legend.position = "bottom")
g3

gapminder1 <- gapminder
gapminder1$year <- as.Date(as.character(gapminder1$year), format = "%Y")
g4 <- gapminder1 %>% filter(country %in% c("Brazil", "China")) %>% ggplot(aes(x = year, y = gdpPercap, color = country)) + geom_line(size = 2) + theme_bw() + scale_color_manual(values = c("darkblue", "lightblue")) + ggtitle("График №4. Шкала с валютой и датой") + scale_y_continuous(labels=scales::dollar_format()) +
scale_x_date(date_breaks ="5 year",date_labels = "'%y") + theme(legend.position = "bottom")
g4
