包中的数据集

包含数据的包或专门用于传播数据集的包。当加载这样的包(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()

StackOverflow 文档

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")

StackOverflow 文档