diff --git a/analysis.R b/analysis.R new file mode 100644 index 0000000..3b61ea7 --- /dev/null +++ b/analysis.R @@ -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") \ No newline at end of file diff --git a/data/murders.csv b/data/murders.csv new file mode 100644 index 0000000..8045266 --- /dev/null +++ b/data/murders.csv @@ -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 diff --git a/download-data.R b/download-data.R new file mode 100644 index 0000000..b329453 --- /dev/null +++ b/download-data.R @@ -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) diff --git a/murders.Rproj b/murders.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/murders.Rproj @@ -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 diff --git a/new-file.txt b/new-file.txt new file mode 100644 index 0000000..499adea --- /dev/null +++ b/new-file.txt @@ -0,0 +1,2 @@ +test +adding a line diff --git a/rdas/murders.rda b/rdas/murders.rda new file mode 100644 index 0000000..b091686 Binary files /dev/null and b/rdas/murders.rda differ diff --git a/report.Rmd b/report.Rmd new file mode 100644 index 0000000..661d06c --- /dev/null +++ b/report.Rmd @@ -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() +``` + diff --git a/report.md b/report.md new file mode 100644 index 0000000..d715fa8 --- /dev/null +++ b/report.md @@ -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) diff --git a/report_files/figure-markdown_github/murder-rate-by-state-1.png b/report_files/figure-markdown_github/murder-rate-by-state-1.png new file mode 100644 index 0000000..a0d73fc Binary files /dev/null and b/report_files/figure-markdown_github/murder-rate-by-state-1.png differ diff --git a/tmp.txt b/tmp.txt new file mode 100644 index 0000000..ed041f1 --- /dev/null +++ b/tmp.txt @@ -0,0 +1 @@ +temporary diff --git a/wrangle-data.R b/wrangle-data.R new file mode 100644 index 0000000..53ed991 --- /dev/null +++ b/wrangle-data.R @@ -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")