Lecture 15
Cornell University
INFO 5001 - Fall 2025
October 21, 2025
TODO
.R
) and Quarto documents (.qmd
)ae-13
Note
ae-13
(repo name will be suffixed with your GitHub name).renv::restore()
to install the required packages, open the Quarto document in the repo, and follow along and complete the exercises.Image credit: R4DS
---
title: Gun deaths
author: Your name
date: today
format: html
---
```{r}
#| label: setup
#| include: false
library(tidyverse)
library(rcis)
youth <- gun_deaths |>
filter(age <= 65)
```
# Gun deaths by age
We have data about `r nrow(gun_deaths)` individuals killed by guns. Only `r nrow(gun_deaths) - nrow(youth)` are older than 65. The distribution of the remainder is shown below:
```{r}
#| label: youth-dist
#| echo: false
ggplot(data = youth, mapping = aes(x = age)) +
geom_freqpoly(binwidth = 1)
```
# Gun deaths by race
```{r}
#| label: race-dist
youth |>
mutate(race = fct_infreq(race) |> fct_rev()) |>
ggplot(mapping = aes(y = race)) +
geom_bar() +
labs(y = "Victim race")
```
---
s```
Image credit: Allison Horst
Image credit: Allison Horst
Instructions
gun-deaths.qmd
as an HTML document05:00
eval: true
include: true
echo: true
message: true
or warning: true
cache: false
# A tibble: 9,299 × 53
caseId docketId caseIssuesId dateDecision decisionType usCite sctCite ledCite lexisCite term
<chr> <chr> <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl>
1 1945-001 1945-001-… 1945-001-01… 12/10/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
2 1945-002 1945-002-… 1945-002-01… 12/3/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
3 1945-003 1945-003-… 1945-003-01… 11/13/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
4 1945-004 1945-004-… 1945-004-01… 11/13/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
5 1945-005 1945-005-… 1945-005-01… 11/5/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
6 1945-006 1945-006-… 1945-006-01… 11/5/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
7 1945-007 1945-007-… 1945-007-01… 11/5/1945 2 326 U… 66 S. … 90 L. … 1945 U.S… 1945
8 1945-008 1945-008-… 1945-008-01… 11/5/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
9 1945-009 1945-009-… 1945-009-01… 11/5/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
10 1945-010 1945-010-… 1945-010-01… 12/10/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
# ℹ 9,289 more rows
# ℹ 43 more variables: naturalCourt <dbl>, chief <chr>, docket <chr>, caseName <chr>,
# dateArgument <chr>, dateRearg <chr>, petitioner <dbl>, petitionerState <dbl>, respondent <dbl>,
# respondentState <dbl>, jurisdiction <dbl>, adminAction <dbl>, adminActionState <dbl>,
# threeJudgeFdc <dbl>, caseOrigin <dbl>, caseOriginState <dbl>, caseSource <dbl>,
# caseSourceState <dbl>, lcDisagreement <dbl>, certReason <dbl>, lcDisposition <dbl>,
# lcDispositionDirection <dbl>, declarationUncon <dbl>, caseDisposition <dbl>, …
# A tibble: 9,299 × 53
caseId docketId caseIssuesId dateDecision decisionType usCite sctCite ledCite lexisCite term
<chr> <chr> <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl>
1 1945-001 1945-001-… 1945-001-01… 12/10/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
2 1945-002 1945-002-… 1945-002-01… 12/3/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
3 1945-003 1945-003-… 1945-003-01… 11/13/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
4 1945-004 1945-004-… 1945-004-01… 11/13/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
5 1945-005 1945-005-… 1945-005-01… 11/5/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
6 1945-006 1945-006-… 1945-006-01… 11/5/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
7 1945-007 1945-007-… 1945-007-01… 11/5/1945 2 326 U… 66 S. … 90 L. … 1945 U.S… 1945
8 1945-008 1945-008-… 1945-008-01… 11/5/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
9 1945-009 1945-009-… 1945-009-01… 11/5/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
10 1945-010 1945-010-… 1945-010-01… 12/10/1945 1 326 U… 66 S. … 90 L. … 1945 U.S… 1945
# ℹ 9,289 more rows
# ℹ 43 more variables: naturalCourt <dbl>, chief <chr>, docket <chr>, caseName <chr>,
# dateArgument <chr>, dateRearg <chr>, petitioner <dbl>, petitionerState <dbl>, respondent <dbl>,
# respondentState <dbl>, jurisdiction <dbl>, adminAction <dbl>, adminActionState <dbl>,
# threeJudgeFdc <dbl>, caseOrigin <dbl>, caseOriginState <dbl>, caseSource <dbl>,
# caseSourceState <dbl>, lcDisagreement <dbl>, certReason <dbl>, lcDisposition <dbl>,
# lcDispositionDirection <dbl>, declarationUncon <dbl>, caseDisposition <dbl>, …
# A tibble: 29,021 × 53
caseId docketId caseIssuesId dateDecision decisionType usCite sctCite ledCite lexisCite term
<chr> <chr> <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl>
1 1791-001 1791-001-… 1791-001-01… 8/3/1791 6 2 U.S… <NA> 1 L. E… 1791 U.S… 1791
2 1791-002 1791-002-… 1791-002-01… 8/3/1791 2 2 U.S… <NA> 1 L. E… 1791 U.S… 1791
3 1792-001 1792-001-… 1792-001-01… 2/14/1792 2 2 U.S… <NA> 1 L. E… 1792 U.S… 1792
4 1792-002 1792-002-… 1792-002-01… 8/7/1792 2 2 U.S… <NA> 1 L. E… 1792 U.S… 1792
5 1792-003 1792-003-… 1792-003-01… 8/11/1792 8 2 U.S… <NA> 1 L. E… 1792 U.S… 1792
6 1792-004 1792-004-… 1792-004-01… 8/11/1792 6 2 U.S… <NA> 1 L. E… 1792 U.S… 1792
7 1793-001 1793-001-… 1793-001-01… 2/19/1793 8 2 U.S… <NA> 1 L. E… 1793 U.S… 1793
8 1793-002 1793-002-… 1793-002-01… 2/20/1793 2 2 U.S… <NA> 1 L. E… 1793 U.S… 1793
9 1793-003 1793-003-… 1793-003-01… 2/20/1793 8 2 U.S… <NA> 1 L. E… 1793 U.S… 1793
10 1794-001 1794-001-… 1794-001-01… 2/7/1794 NA 3 U.S… <NA> 1 L. E… 1794 U.S… 1794
# ℹ 29,011 more rows
# ℹ 43 more variables: naturalCourt <dbl>, chief <chr>, docket <chr>, caseName <chr>,
# dateArgument <chr>, dateRearg <chr>, petitioner <dbl>, petitionerState <dbl>, respondent <dbl>,
# respondentState <dbl>, jurisdiction <dbl>, adminAction <dbl>, adminActionState <dbl>,
# threeJudgeFdc <dbl>, caseOrigin <dbl>, caseOriginState <dbl>, caseSource <dbl>,
# caseSourceState <dbl>, lcDisagreement <dbl>, certReason <dbl>, lcDisposition <dbl>,
# lcDispositionDirection <dbl>, declarationUncon <dbl>, caseDisposition <dbl>, …
We have data about 100798 individuals killed by guns.
Only 15687 are older than 65.
Instructions
echo: false
for each code cell07:00
.qmd
fileInstructions
07:00
Quarto supports multiple presentation formats
revealjs
(HTML)pptx
(PowerPoint)beamer
(\(\LaTeX\)/PDF)Use the documentation to learn how to implement these formats
# gun-deaths.R
# 2024-10-29
# Examine the distribution of age of victims in gun_deaths
# load packages
library(tidyverse)
library(rcis)
# filter data for under 65
youth <- gun_deaths |>
filter(age <= 65)
# number of individuals under 65 killed
nrow(gun_deaths) - nrow(youth)
# graph the distribution of youth
ggplot(data = youth, mapping = aes(x = age)) +
geom_freqpoly(binwidth = 1)
# graph the distribution of youth, by race
youth |>
mutate(race = fct_infreq(race) |> fct_rev()) |>
ggplot(mapping = aes(y = race)) +
geom_bar() +
labs(y = "Victim race")
source()