knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Some demographic data, for teaching purposes. Please do not distribute this package. For the original mortality data, consult http://mortality.org and follow the instructions there.
demog
is a data package.
You can install the beta version of demog from GitHub with:
devtools::install_github("kjhealy/demog")
drat
While using install_github()
works just fine, it would be nicer to be able to just type install.packages("demog")
or update.packages("demog")
in the ordinary way. We can do this using Dirk Eddelbuettel's drat package. Drat provides a convenient way to make R aware of package repositories other than CRAN.
First, install drat
:
if (!require("drat")) { install.packages("drat") library("drat") }
Then use drat
to tell R about the repository where demog
is hosted:
drat::addRepo("kjhealy")
You can now install demog
:
install.packages("demog")
To ensure that the demog
repository is always available, you can add the following line to your .Rprofile
or .Rprofile.site
file:
drat::addRepo("kjhealy")
With that in place you'll be able to do install.packages("demog")
or update.packages("demog")
and have everything work as you'd expect.
Note that the drat repository only contains data packages that are not on CRAN, so you will never be in danger of grabbing the wrong version of any other package.
The package works best with the tidyverse libraries.
library(tidyverse)
Load the data:
library(demog)
okboomer
britain
library(dplyr) library(ggplot2) britain %>% filter(age < 101) %>% ggplot(aes(x = year, y = age, fill = ntile(male, 100))) + geom_raster() + scale_fill_viridis_c(option = "A", direction = -1) + scale_x_continuous(breaks = seq(1845, 2015, by = 15)) + ylim(c(0, 100)) + guides(fill = guide_legend(nrow = 1, title.position = "top", label.position = "bottom")) + labs(x = "Year", y = "Age", fill = "Male Death Rate Percentile", title = "Male Mortality Rates in England and Wales, 1841-2016", subtitle = "Binned by percentile", caption = "@kjhealy / http://socviz.co. Data: Human Mortality Database.") + theme_minimal() + theme(legend.position = "top", legend.title = element_text(size = 8))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.