包中的資料集
包含資料的包或專門用於傳播資料集的包。當載入這樣的包(library(pkg)
)時,附加的資料集可以作為 R 物件使用; 或者需要使用 data()
函式呼叫它們。
Gapminder
關於國家發展的一個很好的資料集。
library(tidyverse)
library(gapminder)
gapminder %>%
ggplot(aes(x = year, y = lifeExp,
color = continent))+
geom_jitter(size = 1, alpha = .2, width = .75)+
stat_summary(geom = "path", fun.y = mean, size = 1)+
theme_minimal()
2015 年世界人口展望 - 聯合國人口司
讓我們看看世界在 1950 - 2015 年間出生時男性預期壽命如何趨同。
library(tidyverse)
library(forcats)
library(wpp2015)
library(ggjoy)
library(viridis)
library(extrafont)
data(UNlocations)
countries <- UNlocations %>%
filter(location_type == 4) %>%
transmute(name = name %>% paste()) %>%
as_vector()
data(e0M)
e0M %>%
filter(country %in% countries) %>%
select(-last.observed) %>%
gather(period, value, 3:15) %>%
ggplot(aes(x = value, y = period %>% fct_rev()))+
geom_joy(aes(fill = period))+
scale_fill_viridis(discrete = T, option = "B", direction = -1,
begin = .1, end = .9)+
labs(x = "Male life expectancy at birth",
y = "Period",
title = "The world convergence in male life expectancy at birth since 1950",
subtitle = "Data: UNPD World Population Prospects 2015 Revision",
caption = "ikashnitsky.github.io")+
theme_minimal(base_family = "Roboto Condensed", base_size = 15)+
theme(legend.position = "none")