[참고] https://ggplot2tutor.com/
## Observations: 1,704
## Variables: 6
## $ country <fct> Afghanistan, Afghanistan, Afghanistan, Afghanis...
## $ continent <fct> Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia,...
## $ year <int> 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987,...
## $ lifeExp <dbl> 28.801, 30.332, 31.997, 34.020, 36.088, 38.438,...
## $ pop <int> 8425333, 9240934, 10267083, 11537966, 13079460,...
## $ gdpPercap <dbl> 779.4453, 820.8530, 853.1007, 836.1971, 739.981...
gapminder_cleaned <- gapminder %>%
filter(year == "2007") %>%
mutate(
pop2 = pop + 1,
continent = case_when(
continent == "Oceania" ~ "Asia", # continent 변수가 oceania 이면 Asia로 입력
TRUE ~ as.character(continent)
) %>% as.factor %>%
fct_relevel("Asia", "Americas", "Europe", "Africa")
)
gapminder_cleaned
## # A tibble: 142 x 7
## country continent year lifeExp pop gdpPercap pop2
## <fct> <fct> <int> <dbl> <int> <dbl> <dbl>
## 1 Afghanistan Asia 2007 43.8 31889923 975. 31889924
## 2 Albania Europe 2007 76.4 3600523 5937. 3600524
## 3 Algeria Africa 2007 72.3 33333216 6223. 33333217
## 4 Angola Africa 2007 42.7 12420476 4797. 12420477
## 5 Argentina Americas 2007 75.3 40301927 12779. 40301928
## 6 Australia Asia 2007 81.2 20434176 34435. 20434177
## 7 Austria Europe 2007 79.8 8199783 36126. 8199784
## 8 Bahrain Asia 2007 75.6 708573 29796. 708574
## 9 Bangladesh Asia 2007 64.1 150448339 1391. 150448340
## 10 Belgium Europe 2007 79.4 10392226 33693. 10392227
## # ... with 132 more rows
ggplot(data = gapminder_cleaned, aes(x = gdpPercap, y = lifeExp)) +
geom_point(aes(size = pop, color = continent)) +
geom_point(aes(size = pop2), color = "black", shape = 21) +
scale_x_log10(breaks = c(500, 1000, 2000, 4000,
8000, 16000, 32000, 64000)) +
scale_y_continuous(breaks = seq(0, 90, by = 10)) +
scale_color_manual(values = c("#F15772", "#7EEB03",
"#FBE700", "#54D5E9"))
ggplot(data = gapminder_cleaned, aes(x = gdpPercap, y = lifeExp)) +
geom_point(aes(size = pop, color = continent)) +
geom_point(aes(size = pop2), color = "black", shape = 21) +
scale_x_log10(breaks = c(500, 1000, 2000, 4000,
8000, 16000, 32000, 64000)) +
scale_y_continuous(breaks = seq(0, 90, by = 10)) +
scale_color_manual(values = c("#F15772", "#7EEB03",
"#FBE700", "#54D5E9")) +
scale_size_continuous(range = c(1, 30)) +
guides(size = FALSE, color = FALSE) +
labs(
x = "Income",
y = "Life expectancy"
)
ggplot(data = gapminder_cleaned, aes(x = gdpPercap, y = lifeExp)) +
geom_point(aes(size = pop, color = continent)) +
geom_point(aes(size = pop2), color = "black", shape = 21) +
scale_x_log10(breaks = c(500, 1000, 2000, 4000,
8000, 16000, 32000, 64000)) +
scale_y_continuous(breaks = seq(0, 90, by = 10)) +
scale_color_manual(values = c("#F15772", "#7EEB03",
"#FBE700", "#54D5E9")) +
scale_size_continuous(range = c(1, 30)) +
guides(size = FALSE, color = FALSE) +
labs(
x = "Income",
y = "Life expectancy"
) +
theme_minimal() +
theme(
plot.margin = unit(rep(1, 4), "cm"),
panel.grid.minor = element_blank(),
panel.grid.major = element_line(size = 0.2,
color = "#e5e5e5"),
axis.title.y = element_text(margin = margin(r = 15),
size = 11,
family = "Helvetica Neue Light"),
axis.title.x = element_text(margin = margin(t = 15),
size = 11,
family = "Helvetica Neue Light"),
axis.text = element_text(family = "Helvetica Neue Light"),
axis.line = element_line(color = "#999999",
size = 0.2)
) +
coord_cartesian(ylim = c(4.1, 86))