Skip to content

Instantly share code, notes, and snippets.

@JosiahParry
Last active August 5, 2019 02:00
Show Gist options
  • Save JosiahParry/ec025f80854f6be2d35c756c0c690a81 to your computer and use it in GitHub Desktop.
Save JosiahParry/ec025f80854f6be2d35c756c0c690a81 to your computer and use it in GitHub Desktop.
---
title: "∑ { _my parts_ }"
output: github_document
---
```{r message=FALSE, warning=FALSE}
library(tidyverse)
terrorists <- googlesheets::gs_url("https://docs.google.com/spreadsheets/d/1LYQakIwGosibDHJKJqZgjM39qpSlp_gFG29zJ6paDAI/edit#gid=956062857") %>%
googlesheets::gs_read()
```
```{r include=FALSE}
terrorist_by_race <- terrorists %>%
group_by(race) %>%
summarise(n = n(),
fatalities = sum(fatalities),
injured = sum(injured),
total_victims = sum(total_victims)) %>%
ungroup() %>%
mutate(`%` = (total_victims / sum(total_victims)) * 100) %>%
arrange(-`%`)
```
```{r echo=FALSE}
terrorist_by_race %>%
mutate(race = fct_reorder(race, total_victims)) %>%
ggplot(aes(race, total_victims)) +
geom_col() +
theme_minimal() +
coord_flip() +
labs(title = "US mass shootings casualties",
caption = "data from Aug. 20th, 1982 - Aug. 4th, 2019",
y = "Total Victims (Dead + Injured)",
x = "Race")
```
```{r}
terrorist_by_race
```
```{r include = FALSE}
terrorist_by_gender <- terrorists %>%
mutate(gender = tolower(gender),
gender = ifelse(gender == "f", "female", gender)) %>%
group_by(gender) %>%
summarise(n = n(),
fatalities = sum(fatalities),
injured = sum(injured),
total_victims = sum(total_victims)) %>%
ungroup() %>%
mutate(`%` = (total_victims / sum(total_victims)) * 100) %>%
arrange(-`%`)
```
```{r echo=FALSE}
terrorist_by_gender %>%
mutate(gender = fct_reorder(gender, total_victims)) %>%
ggplot(aes(gender, total_victims)) +
geom_col() +
theme_minimal() +
coord_flip() +
labs(title = "US mass shootings casualties",
caption = "data from Aug. 20th, 1982 - Aug. 4th, 2019",
y = "Total Victims (Dead + Injured)",
x = "Gender")
```
```{r}
terrorist_by_gender
```
```{r}
terrorist <- c("angry", "white", "male")
my_parts <- c("angry", "white", "male")
```
```{r}
my_parts == terrorist
```
```{r eval=FALSE}
`I am` > sum(parts)
```
```{r echo=FALSE}
TRUE
```
```{r eval=FALSE}
`I am` == sum(terrorist)
```
```{r}
FALSE
```
```{r}
white_males <- filter(terrorists,
race == "white",
tolower(gender) == "male",
!is.na(name))
pull(white_males, name)
```
```{r eval=FALSE}
am_i <- function(terrorist) {
msg <- paste("`I am` ==", terrorist)
print(msg)
print(`I am` == terrorist)
}
```
```{r include=FALSE}
am_i <- function(terrorist) {
msg <- paste("`I am` ==", terrorist)
print(msg)
print(FALSE)
}
```
```{r}
pull(white_males, name) %>%
walk(~am_i(.))
```
```{r eval=FALSE}
`I am` > sum(my_parts)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment