Adding all

This commit is contained in:
shelldweller 2021-07-15 17:26:18 -06:00
parent e237ca69df
commit 0de642bd26
11 changed files with 151 additions and 0 deletions

9
analysis.R Normal file
View File

@ -0,0 +1,9 @@
library(tidyverse)
load("rdas/murders.rda")
murders %>% mutate(abb = reorder(abb, rate)) %>%
ggplot(aes(abb, rate)) +
geom_bar(width = 0.5, stat = "identity", color = "black") +
coord_flip()
ggsave("figs/barplot.png")

52
data/murders.csv Normal file
View File

@ -0,0 +1,52 @@
state,abb,region,population,total
Alabama,AL,South,4779736,135
Alaska,AK,West,710231,19
Arizona,AZ,West,6392017,232
Arkansas,AR,South,2915918,93
California,CA,West,37253956,1257
Colorado,CO,West,5029196,65
Connecticut,CT,Northeast,3574097,97
Delaware,DE,South,897934,38
District of Columbia,DC,South,601723,99
Florida,FL,South,19687653,669
Georgia,GA,South,9920000,376
Hawaii,HI,West,1360301,7
Idaho,ID,West,1567582,12
Illinois,IL,North Central,12830632,364
Indiana,IN,North Central,6483802,142
Iowa,IA,North Central,3046355,21
Kansas,KS,North Central,2853118,63
Kentucky,KY,South,4339367,116
Louisiana,LA,South,4533372,351
Maine,ME,Northeast,1328361,11
Maryland,MD,South,5773552,293
Massachusetts,MA,Northeast,6547629,118
Michigan,MI,North Central,9883640,413
Minnesota,MN,North Central,5303925,53
Mississippi,MS,South,2967297,120
Missouri,MO,North Central,5988927,321
Montana,MT,West,989415,12
Nebraska,NE,North Central,1826341,32
Nevada,NV,West,2700551,84
New Hampshire,NH,Northeast,1316470,5
New Jersey,NJ,Northeast,8791894,246
New Mexico,NM,West,2059179,67
New York,NY,Northeast,19378102,517
North Carolina,NC,South,9535483,286
North Dakota,ND,North Central,672591,4
Ohio,OH,North Central,11536504,310
Oklahoma,OK,South,3751351,111
Oregon,OR,West,3831074,36
Pennsylvania,PA,Northeast,12702379,457
Rhode Island,RI,Northeast,1052567,16
South Carolina,SC,South,4625364,207
South Dakota,SD,North Central,814180,8
Tennessee,TN,South,6346105,219
Texas,TX,South,25145561,805
Utah,UT,West,2763885,22
Vermont,VT,Northeast,625741,2
Virginia,VA,South,8001024,250
Washington,WA,West,6724540,93
West Virginia,WV,South,1852994,27
Wisconsin,WI,North Central,5686986,97
Wyoming,WY,West,563626,5
1 state abb region population total
2 Alabama AL South 4779736 135
3 Alaska AK West 710231 19
4 Arizona AZ West 6392017 232
5 Arkansas AR South 2915918 93
6 California CA West 37253956 1257
7 Colorado CO West 5029196 65
8 Connecticut CT Northeast 3574097 97
9 Delaware DE South 897934 38
10 District of Columbia DC South 601723 99
11 Florida FL South 19687653 669
12 Georgia GA South 9920000 376
13 Hawaii HI West 1360301 7
14 Idaho ID West 1567582 12
15 Illinois IL North Central 12830632 364
16 Indiana IN North Central 6483802 142
17 Iowa IA North Central 3046355 21
18 Kansas KS North Central 2853118 63
19 Kentucky KY South 4339367 116
20 Louisiana LA South 4533372 351
21 Maine ME Northeast 1328361 11
22 Maryland MD South 5773552 293
23 Massachusetts MA Northeast 6547629 118
24 Michigan MI North Central 9883640 413
25 Minnesota MN North Central 5303925 53
26 Mississippi MS South 2967297 120
27 Missouri MO North Central 5988927 321
28 Montana MT West 989415 12
29 Nebraska NE North Central 1826341 32
30 Nevada NV West 2700551 84
31 New Hampshire NH Northeast 1316470 5
32 New Jersey NJ Northeast 8791894 246
33 New Mexico NM West 2059179 67
34 New York NY Northeast 19378102 517
35 North Carolina NC South 9535483 286
36 North Dakota ND North Central 672591 4
37 Ohio OH North Central 11536504 310
38 Oklahoma OK South 3751351 111
39 Oregon OR West 3831074 36
40 Pennsylvania PA Northeast 12702379 457
41 Rhode Island RI Northeast 1052567 16
42 South Carolina SC South 4625364 207
43 South Dakota SD North Central 814180 8
44 Tennessee TN South 6346105 219
45 Texas TX South 25145561 805
46 Utah UT West 2763885 22
47 Vermont VT Northeast 625741 2
48 Virginia VA South 8001024 250
49 Washington WA West 6724540 93
50 West Virginia WV South 1852994 27
51 Wisconsin WI North Central 5686986 97
52 Wyoming WY West 563626 5

3
download-data.R Normal file
View File

@ -0,0 +1,3 @@
url <- "https://raw.githubusercontent.com/rafalab/dslabs/master/inst/extdata/murders.csv"
destination_file <- "data/murders.csv"
download.file(url, destination_file)

13
murders.Rproj Normal file
View File

@ -0,0 +1,13 @@
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX

2
new-file.txt Normal file
View File

@ -0,0 +1,2 @@
test
adding a line

BIN
rdas/murders.rda Normal file

Binary file not shown.

38
report.Rmd Normal file
View File

@ -0,0 +1,38 @@
---
title: "Report on Gun Murders"
author: "Rafael Irizarry"
date: "`r format(Sys.Date())`"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Introduction
This is a report on 2010 gun murder rates obtained from FBI reports. The original data was obtained from [this Wikipedia page](https://en.wikipedia.org/wiki/Murder_in_the_United_States_by_state).
We are going to use the following library:
```{r loading-libs, message=FALSE}
library(tidyverse)
```
and load the data we already wrangled:
```{r}
load("rdas/murders.rda")
```
## Murder rate by state
We note the large state to state variability by generating a barplot showing the murder rate by state:
```{r murder-rate-by-state, echo=FALSE}
murders %>% mutate(abb = reorder(abb, rate)) %>%
ggplot(aes(abb, rate)) +
geom_bar(width = 0.5, stat = "identity", color = "black") +
coord_flip()
```

28
report.md Normal file
View File

@ -0,0 +1,28 @@
Report on Gun Murders
================
Rafael Irizarry
2018-04-16
Introduction
------------
This is a report on 2010 gun murder rates obtained from FBI reports. The original data was obtained from [this Wikipedia page](https://en.wikipedia.org/wiki/Murder_in_the_United_States_by_state).
We are going to use the following library:
``` r
library(tidyverse)
```
and load the data we already wrangled:
``` r
load("rdas/murders.rda")
```
Murder rate by state
--------------------
We note the large state to state variability by generating a barplot showing the murder rate by state:
![](report_files/figure-markdown_github/murder-rate-by-state-1.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

1
tmp.txt Normal file
View File

@ -0,0 +1 @@
temporary

5
wrangle-data.R Normal file
View File

@ -0,0 +1,5 @@
library(tidyverse)
murders <- read_csv("data/murders.csv")
murders <-murders %>% mutate(region = factor(region),
rate = total / population * 10^5)
save(murders, file = "rdas/murders.rda")