library(knitr) desc <- suppressWarnings(readLines("DESCRIPTION")) regex <- "(^Version:\\s+)(\\d+\\.\\d+\\.\\d+)" loc <- grep(regex, desc) ver <- gsub(regex, "\\2", desc[loc]) verbadge <- sprintf('<a href="https://img.shields.io/badge/Version-%s-orange.svg"><img src="https://img.shields.io/badge/Version-%s-orange.svg" alt="Version"/></a></p>', ver, ver) ```` ```r knit_hooks$set(htmlcap = function(before, options, envir) { if(!before) { paste('<p class="caption"><b><em>',options$htmlcap,"</em></b></p>",sep="") } }) knitr::opts_knit$set(self.contained = TRUE, cache = FALSE) knitr::opts_chunk$set(fig.path = "inst/figure/")
sotu: United States Presidential State of the Union Addresses data sets scraped from the American Presidency Project and augmented with demographic data from enchantedlearning.com.
| Data | Type | Description |
|------------------------------|--------------|---------------------------------------------------------|
| sotu
| data.frmae
| United States Presidential State of the Union Addresses |
To download the development version of sotu:
Download the zip ball or tar ball, decompress and run R CMD INSTALL
on it, or use the pacman package to install the development version:
if (!require("pacman")) install.packages("pacman") pacman::p_load_gh("trinker/sotu")
You are welcome to:
- submit suggestions and bug-reports at: https://github.com/trinker/sotu/issues
- send a pull request on: https://github.com/trinker/sotu/
- compose a friendly e-mail to: tyler.rinker@gmail.com
This section demonstrates some analysis that can be conducted with the data set.
if (!require("pacman")) install.packages("pacman") pacman::p_load_gh( "trinker/textshape", "trinker/gofastr", "trinker/termco", "trinker/hclustext" ) pacman::p_load(sotu, dplyr, textshape, ggplot2, tidyr, magrittr) data(sotu)
Initially, when I started looking at the data set I was interested in the ages of Presidents. I was amazed at the ages that early presidents lived too. My wife, Cheryl, suggested I look at this in the context of when the presidents took office. This plot shows the span from inauguration (red dot) to death (black dot) as a gray segment. I can't make any conclusions but it is interesting that many of the mid-section Presidents took office later and lived shorter.
sotu %>% select(President, Start, Died, Born) %>% distinct() %>% mutate( Years = Died - Born, Age = Start - Born ) %>% mutate(President = factor(President, levels=rev(President))) %>% ggplot(aes(y=President)) + geom_segment(aes(x = Age, xend = Years, yend = President), size=4, alpha=.3) + geom_point(aes(x=Years), size=5) + geom_point(aes(x=Age), color="red", size=5)
Cheryl also suggested that the duration of Presidency may effect the age a President lives to. Here I investigated the link between inauguration and death age. I have used a scatterplot and a crude model to investigate this question. The plot doesn't appear to show any trends.
sotu %>% select(President, Start, Died, End, Born) %>% distinct() %>% mutate( YTP = Died - Born, Age = Start - Born, Years = End-Start ) %>% group_by(President) %>% summarize(YTP = min(YTP), Age = min(Age), Years=sum(Years)) %>% ggplot(aes(Age, Years, size=YTP)) + geom_smooth() + geom_point()
Interestingly, the linear model indicates tat the inaugural age of the President has a significant positive effect on death age. Years of presidency has a non-significant negative effect on death age.
sotu %>% select(President, Start, Died, End, Born) %>% distinct() %>% mutate( YTP = Died - Born, Age = Start - Born, Years = End-Start ) %>% group_by(President) %>% summarize(YTP = min(YTP), Age = min(Age), Years=sum(Years)) %>% with(lm(Age ~ YTP + Years)) %T>% {print(summary(.))} %>% anova()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.