library(tidyverse)
library(dplyr)
library(ggplot2)
gdp_data_url <- "https://raw.githubusercontent.com/andrewbowen19/cunyDATA607/main/data/gdp-wide-data.csv"
gdp <- read.csv(gdp_data_url, header=TRUE, skip=5)

head(gdp)
##   Line                                 X      Q1      Q2      Q3      Q4
## 1    1            Gross domestic product 21538.0 19636.7 21362.4 21704.7
## 2    2 Personal consumption expenditures 14440.2 13049.8 14388.7 14586.0
## 3    3                             Goods  4532.2  4344.3  4897.0  4907.1
## 4    4                     Durable goods  1495.3  1486.5  1796.5  1808.8
## 5    5                  Nondurable goods  3036.9  2857.8  3100.4  3098.3
## 6    6                          Services  9907.9  8705.5  9491.7  9679.0
##      Q1.1    Q2.1    Q3.1    Q4.1    Q1.2    Q2.2
## 1 22313.9 23046.9 23550.4 24349.1 24740.5 25248.5
## 2 15131.5 15813.5 16147.3 16518.0 16874.8 17261.3
## 3  5265.3  5529.9  5517.1  5673.7  5843.2  5953.6
## 4  1990.9  2113.5  2035.0  2101.6  2183.9  2181.8
## 5  3274.4  3416.4  3482.2  3572.1  3659.3  3771.9
## 6  9866.2 10283.6 10630.2 10844.3 11031.6 11307.7

Re-naming some columns for readability

gdp <- gdp %>%
          dplyr::rename("category" = "X",
                        "2020.Q1" = "Q1",
                        "2020.Q2" = "Q2",
                        "2020.Q3" = "Q3",
                        "2020.Q4" = "Q4",
                        "2021.Q1" = "Q1.1",
                        "2021.Q2" = "Q2.1",
                        "2021.Q3" = "Q3.1",
                        "2021.Q4" = "Q4.1",
                        "2022.Q1" = "Q1.2",
                        "2022.Q2" = "Q2.2",
                        
                        )

head(gdp)
##   Line                          category 2020.Q1 2020.Q2 2020.Q3 2020.Q4
## 1    1            Gross domestic product 21538.0 19636.7 21362.4 21704.7
## 2    2 Personal consumption expenditures 14440.2 13049.8 14388.7 14586.0
## 3    3                             Goods  4532.2  4344.3  4897.0  4907.1
## 4    4                     Durable goods  1495.3  1486.5  1796.5  1808.8
## 5    5                  Nondurable goods  3036.9  2857.8  3100.4  3098.3
## 6    6                          Services  9907.9  8705.5  9491.7  9679.0
##   2021.Q1 2021.Q2 2021.Q3 2021.Q4 2022.Q1 2022.Q2
## 1 22313.9 23046.9 23550.4 24349.1 24740.5 25248.5
## 2 15131.5 15813.5 16147.3 16518.0 16874.8 17261.3
## 3  5265.3  5529.9  5517.1  5673.7  5843.2  5953.6
## 4  1990.9  2113.5  2035.0  2101.6  2183.9  2181.8
## 5  3274.4  3416.4  3482.2  3572.1  3659.3  3771.9
## 6  9866.2 10283.6 10630.2 10844.3 11031.6 11307.7
gdp$category
##  [1] "        Gross domestic product"                          
##  [2] "Personal consumption expenditures"                       
##  [3] "    Goods"                                               
##  [4] "        Durable goods"                                   
##  [5] "        Nondurable goods"                                
##  [6] "    Services"                                            
##  [7] "Gross private domestic investment"                       
##  [8] "    Fixed investment"                                    
##  [9] "        Nonresidential"                                  
## [10] "            Structures"                                  
## [11] "            Equipment"                                   
## [12] "            Intellectual property products"              
## [13] "        Residential"                                     
## [14] "    Change in private inventories"                       
## [15] "Net exports of goods and services"                       
## [16] "    Exports"                                             
## [17] "        Goods"                                           
## [18] "        Services"                                        
## [19] "    Imports"                                             
## [20] "        Goods"                                           
## [21] "        Services"                                        
## [22] "Government consumption expenditures and gross investment"
## [23] "    Federal"                                             
## [24] "        National defense"                                
## [25] "        Nondefense"                                      
## [26] "    State and local"

Need to transpose the dataframe in order to get it into “long format”

gdp <- gdp %>% 
          gather(quarter, GDP, 3:12) 

gdp$category <- trimws(gdp$category, which = c("both")) # trimming whitespace
    

head(gdp)
##   Line                          category quarter     GDP
## 1    1            Gross domestic product 2020.Q1 21538.0
## 2    2 Personal consumption expenditures 2020.Q1 14440.2
## 3    3                             Goods 2020.Q1  4532.2
## 4    4                     Durable goods 2020.Q1  1495.3
## 5    5                  Nondurable goods 2020.Q1  3036.9
## 6    6                          Services 2020.Q1  9907.9

Now let’s make some plots. First let’s get mean GDP by category

gdp_avg <- gdp %>%
              group_by(category) %>%
              summarise(mean_gdp = mean(GDP))
head(gdp_avg)
## # A tibble: 6 × 2
##   category                      mean_gdp
##   <chr>                            <dbl>
## 1 Change in private inventories     10.3
## 2 Durable goods                   1919. 
## 3 Equipment                       1166. 
## 4 Exports                         2460. 
## 5 Federal                         1575. 
## 6 Fixed investment                4020.

Let’s see GDP by category

ggplot(gdp_avg, aes(x =category, y=mean_gdp)) + geom_bar(stat='identity') + theme(axis.text.x = element_text(angle = 90))

Let’s try our hand at a “time series” and compare imorts to exports

imp_exp <-gdp %>%
            dplyr::filter( category == 'Imports' | category == 'Exports')

ggplot(imp_exp, aes(x =quarter, y=GDP, fill=category)) + geom_point(aes(colour=factor(category)))


Dataset 2

Going to use this year’s standings tables from pro-football-reference.com. Want to combine these into one table with all teams. I grabbed the csv files and uploaded them to GitHub, for reproducability.

# library(XML)
# library(RCurl)
# library(htmltools)
library(rvest)
off_url <- "https://www.pro-football-reference.com/years/2022/#team_stats"
content <- read_html(off_url)

tables <- content %>% html_table()
tables
## [[1]]
## # A tibble: 20 × 13
##    Tm         W     L     T     `W-L%` PF    PA    PD    MoV   SoS   SRS   OSRS 
##    <chr>      <chr> <chr> <chr> <chr>  <chr> <chr> <chr> <chr> <chr> <chr> <chr>
##  1 AFC East   AFC … AFC … AFC … AFC E… AFC … AFC … AFC … AFC … AFC … AFC … AFC …
##  2 Buffalo B… 3     1     0     .750   114   58    56    14.0  2.8   16.8  4.9  
##  3 Miami Dol… 3     1     0     .750   98    91    7     1.8   8.5   10.2  6.8  
##  4 New York … 2     2     0     .500   76    101   -25   -6.3  3.1   -3.1  -3.6 
##  5 New Engla… 1     3     0     .250   74    98    -24   -6.0  5.3   -0.7  -2.7 
##  6 AFC North  AFC … AFC … AFC … AFC N… AFC … AFC … AFC … AFC … AFC … AFC … AFC …
##  7 Baltimore… 2     2     0     .500   119   100   19    4.8   5.8   10.5  12.4 
##  8 Cincinnat… 2     2     0     .500   91    70    21    5.3   2.0   7.2   2.9  
##  9 Cleveland… 2     2     0     .500   105   95    10    2.5   -4.2  -1.7  3.6  
## 10 Pittsburg… 1     3     0     .250   74    90    -16   -4.0  0.4   -3.6  -2.9 
## 11 AFC South  AFC … AFC … AFC … AFC S… AFC … AFC … AFC … AFC … AFC … AFC … AFC …
## 12 Jacksonvi… 2     2     0     .500   105   67    38    9.5   1.6   11.1  9.1  
## 13 Tennessee… 2     2     0     .500   75    101   -26   -6.5  0.0   -6.5  -0.6 
## 14 Indianapo… 2     2     1     .500   69    94    -25   -5.0  -1.6  -6.6  -11.9
## 15 Houston T… 0     3     1     .125   73    93    -20   -5.0  -6.2  -11.2 -1.6 
## 16 AFC West   AFC … AFC … AFC … AFC W… AFC … AFC … AFC … AFC … AFC … AFC … AFC …
## 17 Kansas Ci… 3     1     0     .750   129   96    33    8.3   -2.8  5.5   13.8 
## 18 Los Angel… 2     2     0     .500   92    108   -16   -4.0  -0.5  -4.5  -4.8 
## 19 Denver Br… 2     3     0     .400   75    80    -5    -1.0  -6.6  -7.6  -9.6 
## 20 Las Vegas… 1     3     0     .250   96    100   -4    -1.0  -6.4  -7.4  0.9  
## # … with 1 more variable: DSRS <chr>
## 
## [[2]]
## # A tibble: 20 × 13
##    Tm         W     L     T     `W-L%` PF    PA    PD    MoV   SoS   SRS   OSRS 
##    <chr>      <chr> <chr> <chr> <chr>  <chr> <chr> <chr> <chr> <chr> <chr> <chr>
##  1 NFC East   NFC … NFC … NFC … NFC E… NFC … NFC … NFC … NFC … NFC … NFC … NFC …
##  2 Philadelp… 4     0     0     1.000  115   71    44    11.0  5.0   16.0  7.0  
##  3 Dallas Co… 3     1     0     .750   71    62    9     2.3   2.2   4.4   0.1  
##  4 New York … 3     1     0     .750   76    71    5     1.3   -3.9  -2.7  -3.5 
##  5 Washingto… 1     3     0     .250   73    107   -34   -8.5  8.7   0.2   -3.0 
##  6 NFC North  NFC … NFC … NFC … NFC N… NFC … NFC … NFC … NFC … NFC … NFC … NFC …
##  7 Minnesota… 3     1     0     .750   86    80    6     1.5   4.2   5.7   -2.5 
##  8 Green Bay… 3     1     0     .750   75    69    6     1.5   1.1   2.6   1.8  
##  9 Chicago B… 2     2     0     .500   64    77    -13   -3.3  -2.8  -6.1  -6.2 
## 10 Detroit L… 1     3     0     .250   140   141   -1    -0.3  3.3   3.1   16.4 
## 11 NFC South  NFC … NFC … NFC … NFC S… NFC … NFC … NFC … NFC … NFC … NFC … NFC …
## 12 Tampa Bay… 2     2     0     .500   82    68    14    3.5   1.9   5.4   -3.4 
## 13 Atlanta F… 2     2     0     .500   103   101   2     0.5   -4.6  -4.1  -1.4 
## 14 New Orlea… 1     3     0     .250   76    96    -20   -5.0  0.3   -4.7  0.7  
## 15 Carolina … 1     3     0     .250   78    85    -7    -1.8  -4.4  -6.1  -5.4 
## 16 NFC West   NFC … NFC … NFC … NFC W… NFC … NFC … NFC … NFC … NFC … NFC … NFC …
## 17 Arizona C… 2     2     0     .500   88    103   -15   -3.8  -3.1  -6.9  -5.0 
## 18 Los Angel… 2     2     0     .500   70    94    -24   -6.0  1.4   -4.6  -0.9 
## 19 Seattle S… 2     2     0     .500   95    115   -20   -5.0  -2.2  -7.2  0.0  
## 20 San Franc… 2     2     0     .500   71    46    25    6.3   -6.4  -0.1  -6.2 
## # … with 1 more variable: DSRS <chr>
# Let's break these out by conference
afc <- tables[[1]]
nfc <- tables[[2]]

# Combining and cleaning our two tables
df <- rbind(afc, nfc) 

df <- df %>%
        dplyr::filter(Tm != "NFC East" ,
               Tm != "AFC East" ,
               Tm != "NFC South" ,
               Tm != "AFC South" ,
               Tm != "NFC North" ,
               Tm != "AFC North" ,
               Tm != "NFC West" ,
               Tm != "AFC West"
              ) %>%
        dplyr::rename("wl_pct" = "W-L%")


df
## # A tibble: 32 × 13
##    Tm         W     L     T     wl_pct PF    PA    PD    MoV   SoS   SRS   OSRS 
##    <chr>      <chr> <chr> <chr> <chr>  <chr> <chr> <chr> <chr> <chr> <chr> <chr>
##  1 Buffalo B… 3     1     0     .750   114   58    56    14.0  2.8   16.8  4.9  
##  2 Miami Dol… 3     1     0     .750   98    91    7     1.8   8.5   10.2  6.8  
##  3 New York … 2     2     0     .500   76    101   -25   -6.3  3.1   -3.1  -3.6 
##  4 New Engla… 1     3     0     .250   74    98    -24   -6.0  5.3   -0.7  -2.7 
##  5 Baltimore… 2     2     0     .500   119   100   19    4.8   5.8   10.5  12.4 
##  6 Cincinnat… 2     2     0     .500   91    70    21    5.3   2.0   7.2   2.9  
##  7 Cleveland… 2     2     0     .500   105   95    10    2.5   -4.2  -1.7  3.6  
##  8 Pittsburg… 1     3     0     .250   74    90    -16   -4.0  0.4   -3.6  -2.9 
##  9 Jacksonvi… 2     2     0     .500   105   67    38    9.5   1.6   11.1  9.1  
## 10 Tennessee… 2     2     0     .500   75    101   -26   -6.5  0.0   -6.5  -0.6 
## # … with 22 more rows, and 1 more variable: DSRS <chr>

First, I’d like to see a scatter plot of a team’s point-differential (\(`PF` - `PA`\)) versus a team’s win-loss percentage. Since no teams have had a bye week yet, using win-loss percentage is a better measure of a team’s performance (in terms of winning football games).

ggplot(df, aes(x=PD, y=wl_pct)) + geom_point()

It’s still early in the season (4 games played at the time of this writing), so there aren’t many possible records.


Dataset 3: Gun Violence

Using this gun violence dataset from Kaggle. Since the original file is too big to store on GitHub, I took the first 10000 rows. Will need to tidy up some columns before we can analyze.

library(sf)
## Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(mapview)
gv_url <- "https://raw.githubusercontent.com/andrewbowen19/cunyDATA607/main/data/gun-violence-sample.csv"

gv <- read.csv(gv_url)

head(gv, 15)
##    incident_id       date                state city_or_county
## 1       461105 2013-01-01         Pennsylvania     Mckeesport
## 2       460726 2013-01-01           California      Hawthorne
## 3       478855 2013-01-01                 Ohio         Lorain
## 4       478925 2013-01-05             Colorado         Aurora
## 5       478959 2013-01-07       North Carolina     Greensboro
## 6       478948 2013-01-07             Oklahoma          Tulsa
## 7       479363 2013-01-19           New Mexico    Albuquerque
## 8       479374 2013-01-21            Louisiana    New Orleans
## 9       479389 2013-01-21           California      Brentwood
## 10      492151 2013-01-23             Maryland      Baltimore
## 11      491674 2013-01-23            Tennessee    Chattanooga
## 12      479413 2013-01-25             Missouri    Saint Louis
## 13      479561 2013-01-26            Louisiana      Charenton
## 14      479554 2013-01-26 District of Columbia     Washington
## 15      479460 2013-01-26                 Ohio    Springfield
##                                                address n_killed n_injured
## 1            1506 Versailles Avenue and Coursin Street        0         4
## 2                         13500 block of Cerise Avenue        1         3
## 3                                1776 East 28th Street        1         3
## 4                     16000 block of East Ithaca Place        4         0
## 5                            307 Mourning Dove Terrace        2         2
## 6                           6000 block of South Owasso        4         0
## 7                                       2806 Long Lane        5         0
## 8  LaSalle Street and Martin Luther King Jr. Boulevard        0         5
## 9                           1100 block of Breton Drive        0         4
## 10                        1500 block of W. Fayette St.        1         6
## 11                                      1501 Dodds Ave        1         3
## 12                 W Florissant Ave and Riverview Blvd        1         3
## 13                        1000 block of Flat Town Road        2         3
## 14                         2403 Benning Road Northeast        0         5
## 15                                601 West Main Street        1         3
##                                         incident_url
## 1  http://www.gunviolencearchive.org/incident/461105
## 2  http://www.gunviolencearchive.org/incident/460726
## 3  http://www.gunviolencearchive.org/incident/478855
## 4  http://www.gunviolencearchive.org/incident/478925
## 5  http://www.gunviolencearchive.org/incident/478959
## 6  http://www.gunviolencearchive.org/incident/478948
## 7  http://www.gunviolencearchive.org/incident/479363
## 8  http://www.gunviolencearchive.org/incident/479374
## 9  http://www.gunviolencearchive.org/incident/479389
## 10 http://www.gunviolencearchive.org/incident/492151
## 11 http://www.gunviolencearchive.org/incident/491674
## 12 http://www.gunviolencearchive.org/incident/479413
## 13 http://www.gunviolencearchive.org/incident/479561
## 14 http://www.gunviolencearchive.org/incident/479554
## 15 http://www.gunviolencearchive.org/incident/479460
##                                                                                                                        source_url
## 1   http://www.post-gazette.com/local/south/2013/01/17/Man-arrested-in-New-Year-s-Eve-shooting-in-McKeesport/stories/201301170275
## 2                                                                 http://www.dailybulletin.com/article/zz/20130105/NEWS/130109127
## 3                                    http://chronicle.northcoastnow.com/2013/02/14/2-men-indicted-in-new-years-day-lorain-murder/
## 4                                http://www.dailydemocrat.com/20130106/aurora-shootout-killer-was-frenetic-talented-neighbor-says
## 5                                          http://www.journalnow.com/news/local/article_d4c723e8-5a0f-11e2-a1fa-0019bb30f31a.html
## 6                   http://usnews.nbcnews.com/_news/2013/01/07/16397584-police-four-women-found-dead-in-tulsa-okla-apartment?lite
## 7  http://hinterlandgazette.com/2013/01/pastor-greg-griego-identified-victims-killed-nehemiah-griego-albuquerque-nm-shooting.html
## 8                                                  http://www.nola.com/crime/index.ssf/2013/01/nopd_4_people_shot_in_central.html
## 9                                     http://sanfrancisco.cbslocal.com/2013/01/22/4-teens-hurt-in-drive-by-shooting-in-brentwood/
## 10                            http://www.abc2news.com/news/crime-checker/baltimore-city-crime/mother-of-murdered-15-yo-speaks-out
## 11                                                          http://www.wrcbtv.com/story/22664154/one-dead-in-chattanooga-shooting
## 12                                             http://stlouis.cbslocal.com/2013/01/25/one-dead-four-wounded-in-drive-by-shooting/
## 13                                            http://www.huffingtonpost.com/2013/01/27/wilbert-thibodeaux-arrested_n_2561190.html
## 14                            http://www.washingtontimes.com/news/2013/jan/29/dc-police-release-person-interest-photos-club-shoo/
## 15                                               http://www.whio.com//news/news/crime-law/arrest-made-in-nite-owl-homicide/nWsp4/
##    incident_url_fields_missing congressional_district             gun_stolen
## 1                        False                     14                       
## 2                        False                     43                       
## 3                        False                      9 0::Unknown||1::Unknown
## 4                        False                      6                       
## 5                        False                      6 0::Unknown||1::Unknown
## 6                        False                      1                       
## 7                        False                      1 0::Unknown||1::Unknown
## 8                        False                      2                       
## 9                        False                      9                       
## 10                       False                      7                       
## 11                       False                      3             0::Unknown
## 12                       False                      1             0::Unknown
## 13                       False                      3             0::Unknown
## 14                       False                      1             0::Unknown
## 15                       False                      8                       
##                        gun_type
## 1                              
## 2                              
## 3        0::Unknown||1::Unknown
## 4                              
## 5        0::Handgun||1::Handgun
## 6                              
## 7  0::22 LR||1::223 Rem [AR-15]
## 8                              
## 9                              
## 10                             
## 11                   0::Unknown
## 12                   0::Unknown
## 13                   0::Shotgun
## 14                   0::Handgun
## 15                             
##                                                                                                                                                                                                                                                                                                                                                                                  incident_characteristics
## 1                                                                                                                                                              Shot - Wounded/Injured||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Possession (gun(s) found during commission of other crimes)||Possession of gun by felon or prohibited person
## 2                                                                                                                                                                                                               Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Gang involvement
## 3                                                                                                                                                                                                                                                            Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Shots Fired - No Injuries||Bar/club incident - in or around establishment
## 4                                                                                                                       Shot - Dead (murder, accidental, suicide)||Officer Involved Incident||Officer Involved Shooting - subject/suspect/perpetrator killed||Drug involvement||Kidnapping/abductions/hostage||Under the influence of alcohol or drugs (only applies to the subject/suspect/perpetrator )
## 5                                                                                                                                                                                                                                    Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Suicide^||Murder/Suicide||Attempted Murder/Suicide (one variable unsuccessful)||Domestic Violence
## 6                                                                                                                                           Shot - Dead (murder, accidental, suicide)||Home Invasion||Home Invasion - Resident killed||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Armed robbery with injury/death and/or evidence of DGU found
## 7                                                                                                                                                                                                                                      Shot - Dead (murder, accidental, suicide)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Domestic Violence
## 8                                                                                                                                                                                                                                      Shot - Wounded/Injured||Drive-by (car to street, car to car)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)
## 9                                                                                                                                                                                                                    Shot - Wounded/Injured||Drive-by (car to street, car to car)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Gang involvement
## 10                                                                                                                                                                                                                                Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)
## 11                                                                                                                                                                                                                Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Murder/Suicide||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)
## 12                                                                                                                                                                        Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Drive-by (car to street, car to car)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Gang involvement
## 13 Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Home Invasion||Home Invasion - Resident killed||Officer Involved Incident||Officer Involved Shooting - Officer shot||Officer Involved Shooting - Officer killed||Officer Involved Shooting - subject/suspect/perpetrator shot||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)
## 14                                                                                                                                                                                                                           Shot - Wounded/Injured||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Bar/club incident - in or around establishment
## 15                                                                                                                                                                                Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Bar/club incident - in or around establishment
##    latitude location_description longitude n_guns_involved
## 1   40.3467                       -79.8559              NA
## 2   33.9090                      -118.3330              NA
## 3   41.4455          Cotton Club  -82.1377               2
## 4   39.6518                      -104.8020              NA
## 5   36.1140                       -79.9569               2
## 6   36.2405     Fairmont Terrace  -95.9768              NA
## 7   34.9791                      -106.7160               2
## 8   29.9435                       -90.0836              NA
## 9   37.9656                      -121.7180              NA
## 10  39.2899                       -76.6412              NA
## 11  35.0221                       -85.2697               1
## 12  38.7067                       -90.2494               1
## 13  29.8816                       -91.5251               1
## 14  38.8978                       -76.9717               1
## 15  39.9252      Nite Owl Tavern  -83.8218              NA
##                                                                                                                                                          notes
## 1                                                                                                       Julian Sims under investigation: Four Shot and Injured
## 2                                                                                                   Four Shot; One Killed; Unidentified shooter in getaway car
## 3                                                                                                                                                             
## 4                                                                                                                                                             
## 5                              Two firearms recovered. (Attempted) murder suicide - both succeeded in fulfilling an M/S and did not succeed, based on details.
## 6                                                                                                                                                             
## 7                                                                                                                                                             
## 8                                                  Unprovoked drive-by results in multiple teens and young adults injured. No source with names or exact ages.
## 9                                                                                                              Perps were likely motivated by gang affliations
## 10                                 Shooting occurred over illegal dice game; victim was killed as he sat on a stoop. Victim was not a participant in the game.
## 11                                                                          19 yr. old male dies; 3 inured; shooting on Dodds Ave.;\n\n\n35.022083, -85.269986
## 12                                                                                                                                       38.706732, -90.249375
## 13 Ofc. hailed from Chitimacha Tribe of Louisiana Native American reservation; deputies hailed from St. Mary Parish sheriff's office. Lyons shot before arson.
## 14                                               Media accounts conflict as to gender of victims - there were either 2 women, 3 men wounded OR 1 woman, 4 men.
## 15                                                                                                                                                            
##                          participant_age
## 1                                  0::20
## 2                                  0::20
## 3      0::25||1::31||2::33||3::34||4::33
## 4             0::29||1::33||2::56||3::33
## 5             0::18||1::46||2::14||3::47
## 6             0::23||1::23||2::33||3::55
## 7  0::51||1::40||2::9||3::5||4::2||5::15
## 8                                       
## 9                                       
## 10                                 0::15
## 11                                 0::19
## 12                                 0::28
## 13                          3::78||4::48
## 14                                      
## 15     0::34||1::28||2::23||3::29||4::29
##                                                                                participant_age_group
## 1                               0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+
## 2                                             0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+
## 3                               0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+
## 4                                             0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+
## 5                                            0::Adult 18+||1::Adult 18+||2::Teen 12-17||3::Adult 18+
## 6                 0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+||5::Adult 18+
## 7             0::Adult 18+||1::Adult 18+||2::Child 0-11||3::Child 0-11||4::Child 0-11||5::Teen 12-17
## 8                                                                                                   
## 9                                          0::Teen 12-17||1::Teen 12-17||2::Teen 12-17||4::Adult 18+
## 10 0::Teen 12-17||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+||5::Adult 18+||6::Adult 18+
## 11                                                                                      0::Adult 18+
## 12                                                                                      0::Adult 18+
## 13                              0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+
## 14                0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+||5::Adult 18+
## 15                              0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+
##                                              participant_gender
## 1                          0::Male||1::Male||3::Male||4::Female
## 2                                                       0::Male
## 3                   0::Male||1::Male||2::Male||3::Male||4::Male
## 4                          0::Female||1::Male||2::Male||3::Male
## 5                        0::Female||1::Male||2::Male||3::Female
## 6  0::Female||1::Female||2::Female||3::Female||4::Male||5::Male
## 7    0::Male||1::Female||2::Male||3::Female||4::Female||5::Male
## 8                   0::Male||1::Male||2::Male||3::Male||4::Male
## 9                   0::Male||1::Male||2::Male||3::Male||4::Male
## 10                                                      0::Male
## 11                           0::Male||1::Male||2::Male||3::Male
## 12                                                      0::Male
## 13                  0::Male||1::Male||2::Male||3::Male||4::Male
## 14     0::Female||1::Female||2::Male||3::Male||4::Male||5::Male
## 15                  0::Male||1::Male||2::Male||3::Male||4::Male
##                                                                                              participant_name
## 1                                                                                              0::Julian Sims
## 2                                                                                           0::Bernard Gillis
## 3                        0::Damien Bell||1::Desmen Noble||2::Herman Seagers||3::Ladd Tate Sr||4::Tallis Moore
## 4                         0::Stacie Philbrook||1::Christopher Ratliffe||2::Anthony Ticali||3::Sonny Archuleta
## 5         0::Danielle Imani Jameison||1::Maurice Eugene Edmonds, Sr.||2::Maurice Edmonds II||3::Sandra Palmer
## 6   0::Rebeika Powell||1::Kayetie Melchor||2::Misty Nunley||3::Julie Jackson||4::James Poore||5::Cedric Poore
## 7  0::Greg Griego||1::Sara Griego||2::Zephania Griego||3::Jael Griego||4::Angelina Griego||5::Nehemiah Griego
## 8                                                                                                            
## 9                                                                                                            
## 10                                                                                           0::Deshaun Jones
## 11                                                                                         0::Demetrius Davis
## 12                                                                                      0::Terry Robinson Jr.
## 13                                           0::Ofc.||1::Dep.||2::Dep.||3::Eddie Lyons||4::Wilbert Thibodeaux
## 14                                                                                                           
## 15            0::Ernest Edwards||1::Anthony Clark||2::Joshua Clay||3::Richard Arnold||4::Julian Anwar Johnson
##    participant_relationship
## 1                          
## 2                          
## 3                          
## 4                          
## 5                 3::Family
## 6                          
## 7                 5::Family
## 8                          
## 9                          
## 10                         
## 11                         
## 12                         
## 13                         
## 14                         
## 15                         
##                                                                          participant_status
## 1                               0::Arrested||1::Injured||2::Injured||3::Injured||4::Injured
## 2                                             0::Killed||1::Injured||2::Injured||3::Injured
## 3  0::Injured, Unharmed, Arrested||1::Unharmed, Arrested||2::Killed||3::Injured||4::Injured
## 4                                                0::Killed||1::Killed||2::Killed||3::Killed
## 5                                              0::Injured||1::Injured||2::Killed||3::Killed
## 6  0::Killed||1::Killed||2::Killed||3::Killed||4::Unharmed, Arrested||5::Unharmed, Arrested
## 7              0::Killed||1::Killed||2::Killed||3::Killed||4::Killed||5::Unharmed, Arrested
## 8                                0::Injured||1::Injured||2::Injured||3::Injured||4::Injured
## 9                               0::Injured||1::Injured||2::Injured||3::Injured||4::Unharmed
## 10        0::Killed||1::Injured||2::Injured||3::Injured||4::Injured||5::Injured||6::Injured
## 11                                            0::Killed||1::Injured||2::Injured||3::Injured
## 12                                            0::Killed||1::Injured||2::Injured||3::Injured
## 13                       0::Killed||1::Injured||2::Injured||3::Killed||4::Injured, Arrested
## 14                  0::Injured||1::Injured||2::Injured||3::Injured||4::Injured||5::Unharmed
## 15                     0::Killed||1::Injured||2::Injured||3::Injured||4::Unharmed, Arrested
##                                                                      participant_type
## 1                      0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 2                      0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 3             0::Subject-Suspect||1::Subject-Suspect||2::Victim||3::Victim||4::Victim
## 4                                 0::Victim||1::Victim||2::Victim||3::Subject-Suspect
## 5                                 0::Victim||1::Victim||2::Victim||3::Subject-Suspect
## 6  0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect||5::Subject-Suspect
## 7           0::Victim||1::Victim||2::Victim||3::Victim||4::Victim||5::Subject-Suspect
## 8           0::Victim||1::Victim||2::Victim||3::Victim||4::Victim||5::Subject-Suspect
## 9                      0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 10        0::Victim||1::Victim||2::Victim||3::Victim||4::Victim||5::Victim||6::Victim
## 11                     0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 12                     0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 13                     0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 14          0::Victim||1::Victim||2::Victim||3::Victim||4::Victim||5::Subject-Suspect
## 15                     0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   sources
## 1                                                                                                                                                                                                                                                                              http://pittsburgh.cbslocal.com/2013/01/01/4-people-shot-in-mckeesport/||http://www.wtae.com/news/local/allegheny/U-S-Marshals-task-force-arrests-New-Year-s-party-shooting-suspect/17977588||http://www.post-gazette.com/local/south/2013/01/17/Man-arrested-in-New-Year-s-Eve-shooting-in-McKeesport/stories/201301170275
## 2                                                                                                                                                                                                                                                                           http://losangeles.cbslocal.com/2013/01/01/man-killed-3-wounded-at-nye-party-in-hawthorne/||http://latimesblogs.latimes.com/lanow/2013/01/hawthorne-new-year-party-three-killed.html||https://usgunviolence.wordpress.com/2013/01/01/killed-man-hawthorne-ca/||http://www.dailybulletin.com/article/zz/20130105/NEWS/130109127
## 3                                                                                                                                                                                                                                                                                                                                                                                                        http://www.morningjournal.com/general-news/20130222/lorain-man-pleads-innocent-to-new-years-murder||http://chronicle.northcoastnow.com/2013/02/14/2-men-indicted-in-new-years-day-lorain-murder/
## 4                                                           http://denver.cbslocal.com/2013/01/06/officer-told-neighbor-standoff-gunman-was-on-meth-binge/||http://www.westword.com/news/sonny-archuleta-triple-murder-in-aurora-guns-purchased-legally-55-57-5900504||http://www.denverpost.com/ci_22322380/aurora-shooter-was-frenetic-talented-neighbor-says||http://www.dailymail.co.uk/news/article-2258008/Sonny-Archuleta-Gunman-left-dead-latest-Aurora-shooting-lost-brother-gun-violence.html||http://www.dailydemocrat.com/20130106/aurora-shootout-killer-was-frenetic-talented-neighbor-says
## 5                                                                                                                                                                                                                                                                                                                     http://myfox8.com/2013/01/08/update-mother-shot-14-year-old-son-two-others-before-killing-herself/||http://myfox8.com/2013/01/07/police-respond-to-report-of-triple-shooting-in-greensboro/||http://www.journalnow.com/news/local/article_d4c723e8-5a0f-11e2-a1fa-0019bb30f31a.html
## 6                                                                  http://www.kjrh.com/news/local-news/4-found-shot-inside-apartment-in-tulsa||http://www.cbsnews.com/news/tulsa-apartment-murders-update-hearing-scheduled-for-brothers-charged-in-quadruple-killing/||http://www.kjrh.com/news/local-news/hearing-continues-for-fairmont-terrace-quadruple-homicide-suspect-cedric-poore-james-poore||http://www.kjrh.com/news/local-news/hearing-for-quadruple-murder-suspects-continue||http://usnews.nbcnews.com/_news/2013/01/07/16397584-police-four-women-found-dead-in-tulsa-okla-apartment?lite
## 7  http://www.cbsnews.com/news/nehemiah-gringo-case-memorial-service-planned-for-family-allegedly-slain-by-new-mexico-teen/||http://www.thewire.com/national/2013/01/teenager-reportedly-used-ar-15-kill-five-new-mexico/61199/||http://bigstory.ap.org/article/officials-nm-teen-gunman-kills-5-inside-home||http://www.huffingtonpost.com/2013/01/21/nehemiah-griego-teen-shoots-parents-3-children_n_2519359.html||http://murderpedia.org/male.G/g/griego-nehemiah.htm||http://hinterlandgazette.com/2013/01/pastor-greg-griego-identified-victims-killed-nehemiah-griego-albuquerque-nm-shooting.html
## 8                                                                                                                                                                                                                                                                                                                                                                          http://www.huffingtonpost.com/2013/01/21/new-orleans-mlk-day-shooting_n_2521750.html||http://www.fox8live.com/story/20640921/nopd-4-shot-alomg||http://www.nola.com/crime/index.ssf/2013/01/nopd_4_people_shot_in_central.html
## 9                                                                                                                                                                                                                                                                                                                                                                                                                   http://www.contracostatimes.com/ci_22426767/brentwood-teens-may-have-been-shot-over-nike||http://sanfrancisco.cbslocal.com/2013/01/22/4-teens-hurt-in-drive-by-shooting-in-brentwood/
## 10                                                                                                                                                                                                                                                                         http://articles.baltimoresun.com/2013-08-25/news/bs-md-ci-shootings-20130824_1_west-baltimore-15-year-old-boy-shooting-incidents||http://baltimore.cbslocal.com/2013/08/25/juvenile-dead-6-shot-after-dice-game-goes-bad/||http://www.abc2news.com/news/crime-checker/baltimore-city-crime/mother-of-murdered-15-yo-speaks-out
## 11                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  http://www.wrcbtv.com/story/22664154/one-dead-in-chattanooga-shooting
## 12                                                                                                                                                                                                                                                                                                       http://fox2now.com/2013/01/25/two-shot-in-north-st-louis/||http://www.stltoday.com/news/local/crime-and-courts/st-louis-police-seek-white-suv-in-shootings/article_2b4dcbcb-f885-5c96-b41f-bdf5a9674c98.html||http://stlouis.cbslocal.com/2013/01/25/one-dead-four-wounded-in-drive-by-shooting/
## 13                                                                                                http://theadvocate.com/home/5018249-125/3-law-enforcement-officers-shot||http://www.dailymail.co.uk/news/article-2268979/Wilbert-Thibodeaux-Gunman-slays-lawman-wounds-torching-mobile-home.html||http://www.foxnews.com/us/2013/01/26/trooper-officer-killed-2-sheriff-deputies-wounded-in-la-shooting-suspect-in.html||http://www.tlgnewspaper.com/man-arrested-after-officer-killed-2-sheriff039s-deputies-hurt||http://www.huffingtonpost.com/2013/01/27/wilbert-thibodeaux-arrested_n_2561190.html
## 14                                                                                                                                                        http://www.washingtonexaminer.com/d.c.-nightclub-shooting-leaves-5-injured/article/2519778||http://www.nbcwashington.com/news/local/Five-Injured-in-DC-Nightclub-Shooting-188481201.html||http://thefabempire.com/2013/01/26/five-injured-in-shooting-at-d-c-soundstage/||http://dcist.com/2013/01/five_shot_sunday_morning_at_northea.php||http://www.washingtontimes.com/news/2013/jan/29/dc-police-release-person-interest-photos-club-shoo/
## 15                                                                                                                                                                                                                                       http://www.daytondailynews.com/news/news/1-dead-3-injured-in-tavern-shooting/nT77k/||http://www.springfieldnewssun.com/news/news/crime-law/family-mourns-bar-shooting-victim/nWwmT/||http://www.whio.com/news/news/crime-law/man-sentenced-8-years-springfield-homicide/nc4BY/||http://www.whio.com//news/news/crime-law/arrest-made-in-nite-owl-homicide/nWsp4/
##    state_house_district state_senate_district
## 1                    NA                    NA
## 2                    62                    35
## 3                    56                    13
## 4                    40                    28
## 5                    62                    27
## 6                    72                    11
## 7                    10                    14
## 8                    93                     5
## 9                    11                     7
## 10                   NA                    44
## 11                   28                    10
## 12                   76                     4
## 13                   50                    21
## 14                   NA                    NA
## 15                   79                    10

Let’s start by cleaning up our gun_stolen and gun_type columns. We don’t need the 0:: prefixes, for instance.

gv <- gv %>%
        mutate(gun_type = str_replace_all(gun_type, "^[^\\|]*\\|{2}", "")) %>%
        mutate(gun_stolen = str_replace_all(gun_stolen, "^[^\\|]*\\|", ""))


head(gv, 10)
##    incident_id       date          state city_or_county
## 1       461105 2013-01-01   Pennsylvania     Mckeesport
## 2       460726 2013-01-01     California      Hawthorne
## 3       478855 2013-01-01           Ohio         Lorain
## 4       478925 2013-01-05       Colorado         Aurora
## 5       478959 2013-01-07 North Carolina     Greensboro
## 6       478948 2013-01-07       Oklahoma          Tulsa
## 7       479363 2013-01-19     New Mexico    Albuquerque
## 8       479374 2013-01-21      Louisiana    New Orleans
## 9       479389 2013-01-21     California      Brentwood
## 10      492151 2013-01-23       Maryland      Baltimore
##                                                address n_killed n_injured
## 1            1506 Versailles Avenue and Coursin Street        0         4
## 2                         13500 block of Cerise Avenue        1         3
## 3                                1776 East 28th Street        1         3
## 4                     16000 block of East Ithaca Place        4         0
## 5                            307 Mourning Dove Terrace        2         2
## 6                           6000 block of South Owasso        4         0
## 7                                       2806 Long Lane        5         0
## 8  LaSalle Street and Martin Luther King Jr. Boulevard        0         5
## 9                           1100 block of Breton Drive        0         4
## 10                        1500 block of W. Fayette St.        1         6
##                                         incident_url
## 1  http://www.gunviolencearchive.org/incident/461105
## 2  http://www.gunviolencearchive.org/incident/460726
## 3  http://www.gunviolencearchive.org/incident/478855
## 4  http://www.gunviolencearchive.org/incident/478925
## 5  http://www.gunviolencearchive.org/incident/478959
## 6  http://www.gunviolencearchive.org/incident/478948
## 7  http://www.gunviolencearchive.org/incident/479363
## 8  http://www.gunviolencearchive.org/incident/479374
## 9  http://www.gunviolencearchive.org/incident/479389
## 10 http://www.gunviolencearchive.org/incident/492151
##                                                                                                                        source_url
## 1   http://www.post-gazette.com/local/south/2013/01/17/Man-arrested-in-New-Year-s-Eve-shooting-in-McKeesport/stories/201301170275
## 2                                                                 http://www.dailybulletin.com/article/zz/20130105/NEWS/130109127
## 3                                    http://chronicle.northcoastnow.com/2013/02/14/2-men-indicted-in-new-years-day-lorain-murder/
## 4                                http://www.dailydemocrat.com/20130106/aurora-shootout-killer-was-frenetic-talented-neighbor-says
## 5                                          http://www.journalnow.com/news/local/article_d4c723e8-5a0f-11e2-a1fa-0019bb30f31a.html
## 6                   http://usnews.nbcnews.com/_news/2013/01/07/16397584-police-four-women-found-dead-in-tulsa-okla-apartment?lite
## 7  http://hinterlandgazette.com/2013/01/pastor-greg-griego-identified-victims-killed-nehemiah-griego-albuquerque-nm-shooting.html
## 8                                                  http://www.nola.com/crime/index.ssf/2013/01/nopd_4_people_shot_in_central.html
## 9                                     http://sanfrancisco.cbslocal.com/2013/01/22/4-teens-hurt-in-drive-by-shooting-in-brentwood/
## 10                            http://www.abc2news.com/news/crime-checker/baltimore-city-crime/mother-of-murdered-15-yo-speaks-out
##    incident_url_fields_missing congressional_district  gun_stolen
## 1                        False                     14            
## 2                        False                     43            
## 3                        False                      9 |1::Unknown
## 4                        False                      6            
## 5                        False                      6 |1::Unknown
## 6                        False                      1            
## 7                        False                      1 |1::Unknown
## 8                        False                      2            
## 9                        False                      9            
## 10                       False                      7            
##              gun_type
## 1                    
## 2                    
## 3          1::Unknown
## 4                    
## 5          1::Handgun
## 6                    
## 7  1::223 Rem [AR-15]
## 8                    
## 9                    
## 10                   
##                                                                                                                                                                                                                                                             incident_characteristics
## 1                                         Shot - Wounded/Injured||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Possession (gun(s) found during commission of other crimes)||Possession of gun by felon or prohibited person
## 2                                                                                          Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Gang involvement
## 3                                                                                                                                       Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Shots Fired - No Injuries||Bar/club incident - in or around establishment
## 4  Shot - Dead (murder, accidental, suicide)||Officer Involved Incident||Officer Involved Shooting - subject/suspect/perpetrator killed||Drug involvement||Kidnapping/abductions/hostage||Under the influence of alcohol or drugs (only applies to the subject/suspect/perpetrator )
## 5                                                                                                               Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Suicide^||Murder/Suicide||Attempted Murder/Suicide (one variable unsuccessful)||Domestic Violence
## 6                      Shot - Dead (murder, accidental, suicide)||Home Invasion||Home Invasion - Resident killed||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Armed robbery with injury/death and/or evidence of DGU found
## 7                                                                                                                 Shot - Dead (murder, accidental, suicide)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Domestic Violence
## 8                                                                                                                 Shot - Wounded/Injured||Drive-by (car to street, car to car)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)
## 9                                                                                               Shot - Wounded/Injured||Drive-by (car to street, car to car)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Gang involvement
## 10                                                                                                           Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)
##    latitude location_description longitude n_guns_involved
## 1   40.3467                       -79.8559              NA
## 2   33.9090                      -118.3330              NA
## 3   41.4455          Cotton Club  -82.1377               2
## 4   39.6518                      -104.8020              NA
## 5   36.1140                       -79.9569               2
## 6   36.2405     Fairmont Terrace  -95.9768              NA
## 7   34.9791                      -106.7160               2
## 8   29.9435                       -90.0836              NA
## 9   37.9656                      -121.7180              NA
## 10  39.2899                       -76.6412              NA
##                                                                                                                              notes
## 1                                                                           Julian Sims under investigation: Four Shot and Injured
## 2                                                                       Four Shot; One Killed; Unidentified shooter in getaway car
## 3                                                                                                                                 
## 4                                                                                                                                 
## 5  Two firearms recovered. (Attempted) murder suicide - both succeeded in fulfilling an M/S and did not succeed, based on details.
## 6                                                                                                                                 
## 7                                                                                                                                 
## 8                      Unprovoked drive-by results in multiple teens and young adults injured. No source with names or exact ages.
## 9                                                                                  Perps were likely motivated by gang affliations
## 10     Shooting occurred over illegal dice game; victim was killed as he sat on a stoop. Victim was not a participant in the game.
##                          participant_age
## 1                                  0::20
## 2                                  0::20
## 3      0::25||1::31||2::33||3::34||4::33
## 4             0::29||1::33||2::56||3::33
## 5             0::18||1::46||2::14||3::47
## 6             0::23||1::23||2::33||3::55
## 7  0::51||1::40||2::9||3::5||4::2||5::15
## 8                                       
## 9                                       
## 10                                 0::15
##                                                                                participant_age_group
## 1                               0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+
## 2                                             0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+
## 3                               0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+
## 4                                             0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+
## 5                                            0::Adult 18+||1::Adult 18+||2::Teen 12-17||3::Adult 18+
## 6                 0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+||5::Adult 18+
## 7             0::Adult 18+||1::Adult 18+||2::Child 0-11||3::Child 0-11||4::Child 0-11||5::Teen 12-17
## 8                                                                                                   
## 9                                          0::Teen 12-17||1::Teen 12-17||2::Teen 12-17||4::Adult 18+
## 10 0::Teen 12-17||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+||5::Adult 18+||6::Adult 18+
##                                              participant_gender
## 1                          0::Male||1::Male||3::Male||4::Female
## 2                                                       0::Male
## 3                   0::Male||1::Male||2::Male||3::Male||4::Male
## 4                          0::Female||1::Male||2::Male||3::Male
## 5                        0::Female||1::Male||2::Male||3::Female
## 6  0::Female||1::Female||2::Female||3::Female||4::Male||5::Male
## 7    0::Male||1::Female||2::Male||3::Female||4::Female||5::Male
## 8                   0::Male||1::Male||2::Male||3::Male||4::Male
## 9                   0::Male||1::Male||2::Male||3::Male||4::Male
## 10                                                      0::Male
##                                                                                              participant_name
## 1                                                                                              0::Julian Sims
## 2                                                                                           0::Bernard Gillis
## 3                        0::Damien Bell||1::Desmen Noble||2::Herman Seagers||3::Ladd Tate Sr||4::Tallis Moore
## 4                         0::Stacie Philbrook||1::Christopher Ratliffe||2::Anthony Ticali||3::Sonny Archuleta
## 5         0::Danielle Imani Jameison||1::Maurice Eugene Edmonds, Sr.||2::Maurice Edmonds II||3::Sandra Palmer
## 6   0::Rebeika Powell||1::Kayetie Melchor||2::Misty Nunley||3::Julie Jackson||4::James Poore||5::Cedric Poore
## 7  0::Greg Griego||1::Sara Griego||2::Zephania Griego||3::Jael Griego||4::Angelina Griego||5::Nehemiah Griego
## 8                                                                                                            
## 9                                                                                                            
## 10                                                                                           0::Deshaun Jones
##    participant_relationship
## 1                          
## 2                          
## 3                          
## 4                          
## 5                 3::Family
## 6                          
## 7                 5::Family
## 8                          
## 9                          
## 10                         
##                                                                          participant_status
## 1                               0::Arrested||1::Injured||2::Injured||3::Injured||4::Injured
## 2                                             0::Killed||1::Injured||2::Injured||3::Injured
## 3  0::Injured, Unharmed, Arrested||1::Unharmed, Arrested||2::Killed||3::Injured||4::Injured
## 4                                                0::Killed||1::Killed||2::Killed||3::Killed
## 5                                              0::Injured||1::Injured||2::Killed||3::Killed
## 6  0::Killed||1::Killed||2::Killed||3::Killed||4::Unharmed, Arrested||5::Unharmed, Arrested
## 7              0::Killed||1::Killed||2::Killed||3::Killed||4::Killed||5::Unharmed, Arrested
## 8                                0::Injured||1::Injured||2::Injured||3::Injured||4::Injured
## 9                               0::Injured||1::Injured||2::Injured||3::Injured||4::Unharmed
## 10        0::Killed||1::Injured||2::Injured||3::Injured||4::Injured||5::Injured||6::Injured
##                                                                      participant_type
## 1                      0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 2                      0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 3             0::Subject-Suspect||1::Subject-Suspect||2::Victim||3::Victim||4::Victim
## 4                                 0::Victim||1::Victim||2::Victim||3::Subject-Suspect
## 5                                 0::Victim||1::Victim||2::Victim||3::Subject-Suspect
## 6  0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect||5::Subject-Suspect
## 7           0::Victim||1::Victim||2::Victim||3::Victim||4::Victim||5::Subject-Suspect
## 8           0::Victim||1::Victim||2::Victim||3::Victim||4::Victim||5::Subject-Suspect
## 9                      0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 10        0::Victim||1::Victim||2::Victim||3::Victim||4::Victim||5::Victim||6::Victim
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   sources
## 1                                                                                                                                                                                                                                                                              http://pittsburgh.cbslocal.com/2013/01/01/4-people-shot-in-mckeesport/||http://www.wtae.com/news/local/allegheny/U-S-Marshals-task-force-arrests-New-Year-s-party-shooting-suspect/17977588||http://www.post-gazette.com/local/south/2013/01/17/Man-arrested-in-New-Year-s-Eve-shooting-in-McKeesport/stories/201301170275
## 2                                                                                                                                                                                                                                                                           http://losangeles.cbslocal.com/2013/01/01/man-killed-3-wounded-at-nye-party-in-hawthorne/||http://latimesblogs.latimes.com/lanow/2013/01/hawthorne-new-year-party-three-killed.html||https://usgunviolence.wordpress.com/2013/01/01/killed-man-hawthorne-ca/||http://www.dailybulletin.com/article/zz/20130105/NEWS/130109127
## 3                                                                                                                                                                                                                                                                                                                                                                                                        http://www.morningjournal.com/general-news/20130222/lorain-man-pleads-innocent-to-new-years-murder||http://chronicle.northcoastnow.com/2013/02/14/2-men-indicted-in-new-years-day-lorain-murder/
## 4                                                           http://denver.cbslocal.com/2013/01/06/officer-told-neighbor-standoff-gunman-was-on-meth-binge/||http://www.westword.com/news/sonny-archuleta-triple-murder-in-aurora-guns-purchased-legally-55-57-5900504||http://www.denverpost.com/ci_22322380/aurora-shooter-was-frenetic-talented-neighbor-says||http://www.dailymail.co.uk/news/article-2258008/Sonny-Archuleta-Gunman-left-dead-latest-Aurora-shooting-lost-brother-gun-violence.html||http://www.dailydemocrat.com/20130106/aurora-shootout-killer-was-frenetic-talented-neighbor-says
## 5                                                                                                                                                                                                                                                                                                                     http://myfox8.com/2013/01/08/update-mother-shot-14-year-old-son-two-others-before-killing-herself/||http://myfox8.com/2013/01/07/police-respond-to-report-of-triple-shooting-in-greensboro/||http://www.journalnow.com/news/local/article_d4c723e8-5a0f-11e2-a1fa-0019bb30f31a.html
## 6                                                                  http://www.kjrh.com/news/local-news/4-found-shot-inside-apartment-in-tulsa||http://www.cbsnews.com/news/tulsa-apartment-murders-update-hearing-scheduled-for-brothers-charged-in-quadruple-killing/||http://www.kjrh.com/news/local-news/hearing-continues-for-fairmont-terrace-quadruple-homicide-suspect-cedric-poore-james-poore||http://www.kjrh.com/news/local-news/hearing-for-quadruple-murder-suspects-continue||http://usnews.nbcnews.com/_news/2013/01/07/16397584-police-four-women-found-dead-in-tulsa-okla-apartment?lite
## 7  http://www.cbsnews.com/news/nehemiah-gringo-case-memorial-service-planned-for-family-allegedly-slain-by-new-mexico-teen/||http://www.thewire.com/national/2013/01/teenager-reportedly-used-ar-15-kill-five-new-mexico/61199/||http://bigstory.ap.org/article/officials-nm-teen-gunman-kills-5-inside-home||http://www.huffingtonpost.com/2013/01/21/nehemiah-griego-teen-shoots-parents-3-children_n_2519359.html||http://murderpedia.org/male.G/g/griego-nehemiah.htm||http://hinterlandgazette.com/2013/01/pastor-greg-griego-identified-victims-killed-nehemiah-griego-albuquerque-nm-shooting.html
## 8                                                                                                                                                                                                                                                                                                                                                                          http://www.huffingtonpost.com/2013/01/21/new-orleans-mlk-day-shooting_n_2521750.html||http://www.fox8live.com/story/20640921/nopd-4-shot-alomg||http://www.nola.com/crime/index.ssf/2013/01/nopd_4_people_shot_in_central.html
## 9                                                                                                                                                                                                                                                                                                                                                                                                                   http://www.contracostatimes.com/ci_22426767/brentwood-teens-may-have-been-shot-over-nike||http://sanfrancisco.cbslocal.com/2013/01/22/4-teens-hurt-in-drive-by-shooting-in-brentwood/
## 10                                                                                                                                                                                                                                                                         http://articles.baltimoresun.com/2013-08-25/news/bs-md-ci-shootings-20130824_1_west-baltimore-15-year-old-boy-shooting-incidents||http://baltimore.cbslocal.com/2013/08/25/juvenile-dead-6-shot-after-dice-game-goes-bad/||http://www.abc2news.com/news/crime-checker/baltimore-city-crime/mother-of-murdered-15-yo-speaks-out
##    state_house_district state_senate_district
## 1                    NA                    NA
## 2                    62                    35
## 3                    56                    13
## 4                    40                    28
## 5                    62                    27
## 6                    72                    11
## 7                    10                    14
## 8                    93                     5
## 9                    11                     7
## 10                   NA                    44

Let’s also break up our participant_age column so it’s a bit cleaner for later analysis

gv <- gv  %>%
        mutate(perp_age = str_replace_all(str_extract(participant_age, "[0-9]::(\\d{1,2})"), "\\d::", ""))

head(gv)
##   incident_id       date          state city_or_county
## 1      461105 2013-01-01   Pennsylvania     Mckeesport
## 2      460726 2013-01-01     California      Hawthorne
## 3      478855 2013-01-01           Ohio         Lorain
## 4      478925 2013-01-05       Colorado         Aurora
## 5      478959 2013-01-07 North Carolina     Greensboro
## 6      478948 2013-01-07       Oklahoma          Tulsa
##                                     address n_killed n_injured
## 1 1506 Versailles Avenue and Coursin Street        0         4
## 2              13500 block of Cerise Avenue        1         3
## 3                     1776 East 28th Street        1         3
## 4          16000 block of East Ithaca Place        4         0
## 5                 307 Mourning Dove Terrace        2         2
## 6                6000 block of South Owasso        4         0
##                                        incident_url
## 1 http://www.gunviolencearchive.org/incident/461105
## 2 http://www.gunviolencearchive.org/incident/460726
## 3 http://www.gunviolencearchive.org/incident/478855
## 4 http://www.gunviolencearchive.org/incident/478925
## 5 http://www.gunviolencearchive.org/incident/478959
## 6 http://www.gunviolencearchive.org/incident/478948
##                                                                                                                      source_url
## 1 http://www.post-gazette.com/local/south/2013/01/17/Man-arrested-in-New-Year-s-Eve-shooting-in-McKeesport/stories/201301170275
## 2                                                               http://www.dailybulletin.com/article/zz/20130105/NEWS/130109127
## 3                                  http://chronicle.northcoastnow.com/2013/02/14/2-men-indicted-in-new-years-day-lorain-murder/
## 4                              http://www.dailydemocrat.com/20130106/aurora-shootout-killer-was-frenetic-talented-neighbor-says
## 5                                        http://www.journalnow.com/news/local/article_d4c723e8-5a0f-11e2-a1fa-0019bb30f31a.html
## 6                 http://usnews.nbcnews.com/_news/2013/01/07/16397584-police-four-women-found-dead-in-tulsa-okla-apartment?lite
##   incident_url_fields_missing congressional_district  gun_stolen   gun_type
## 1                       False                     14                       
## 2                       False                     43                       
## 3                       False                      9 |1::Unknown 1::Unknown
## 4                       False                      6                       
## 5                       False                      6 |1::Unknown 1::Handgun
## 6                       False                      1                       
##                                                                                                                                                                                                                                                            incident_characteristics
## 1                                        Shot - Wounded/Injured||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Possession (gun(s) found during commission of other crimes)||Possession of gun by felon or prohibited person
## 2                                                                                         Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Gang involvement
## 3                                                                                                                                      Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Shots Fired - No Injuries||Bar/club incident - in or around establishment
## 4 Shot - Dead (murder, accidental, suicide)||Officer Involved Incident||Officer Involved Shooting - subject/suspect/perpetrator killed||Drug involvement||Kidnapping/abductions/hostage||Under the influence of alcohol or drugs (only applies to the subject/suspect/perpetrator )
## 5                                                                                                              Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Suicide^||Murder/Suicide||Attempted Murder/Suicide (one variable unsuccessful)||Domestic Violence
## 6                     Shot - Dead (murder, accidental, suicide)||Home Invasion||Home Invasion - Resident killed||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, one location)||Armed robbery with injury/death and/or evidence of DGU found
##   latitude location_description longitude n_guns_involved
## 1  40.3467                       -79.8559              NA
## 2  33.9090                      -118.3330              NA
## 3  41.4455          Cotton Club  -82.1377               2
## 4  39.6518                      -104.8020              NA
## 5  36.1140                       -79.9569               2
## 6  36.2405     Fairmont Terrace  -95.9768              NA
##                                                                                                                             notes
## 1                                                                          Julian Sims under investigation: Four Shot and Injured
## 2                                                                      Four Shot; One Killed; Unidentified shooter in getaway car
## 3                                                                                                                                
## 4                                                                                                                                
## 5 Two firearms recovered. (Attempted) murder suicide - both succeeded in fulfilling an M/S and did not succeed, based on details.
## 6                                                                                                                                
##                     participant_age
## 1                             0::20
## 2                             0::20
## 3 0::25||1::31||2::33||3::34||4::33
## 4        0::29||1::33||2::56||3::33
## 5        0::18||1::46||2::14||3::47
## 6        0::23||1::23||2::33||3::55
##                                                                participant_age_group
## 1               0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+
## 2                             0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+
## 3               0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+
## 4                             0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+
## 5                            0::Adult 18+||1::Adult 18+||2::Teen 12-17||3::Adult 18+
## 6 0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+||5::Adult 18+
##                                             participant_gender
## 1                         0::Male||1::Male||3::Male||4::Female
## 2                                                      0::Male
## 3                  0::Male||1::Male||2::Male||3::Male||4::Male
## 4                         0::Female||1::Male||2::Male||3::Male
## 5                       0::Female||1::Male||2::Male||3::Female
## 6 0::Female||1::Female||2::Female||3::Female||4::Male||5::Male
##                                                                                            participant_name
## 1                                                                                            0::Julian Sims
## 2                                                                                         0::Bernard Gillis
## 3                      0::Damien Bell||1::Desmen Noble||2::Herman Seagers||3::Ladd Tate Sr||4::Tallis Moore
## 4                       0::Stacie Philbrook||1::Christopher Ratliffe||2::Anthony Ticali||3::Sonny Archuleta
## 5       0::Danielle Imani Jameison||1::Maurice Eugene Edmonds, Sr.||2::Maurice Edmonds II||3::Sandra Palmer
## 6 0::Rebeika Powell||1::Kayetie Melchor||2::Misty Nunley||3::Julie Jackson||4::James Poore||5::Cedric Poore
##   participant_relationship
## 1                         
## 2                         
## 3                         
## 4                         
## 5                3::Family
## 6                         
##                                                                         participant_status
## 1                              0::Arrested||1::Injured||2::Injured||3::Injured||4::Injured
## 2                                            0::Killed||1::Injured||2::Injured||3::Injured
## 3 0::Injured, Unharmed, Arrested||1::Unharmed, Arrested||2::Killed||3::Injured||4::Injured
## 4                                               0::Killed||1::Killed||2::Killed||3::Killed
## 5                                             0::Injured||1::Injured||2::Killed||3::Killed
## 6 0::Killed||1::Killed||2::Killed||3::Killed||4::Unharmed, Arrested||5::Unharmed, Arrested
##                                                                     participant_type
## 1                     0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 2                     0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect
## 3            0::Subject-Suspect||1::Subject-Suspect||2::Victim||3::Victim||4::Victim
## 4                                0::Victim||1::Victim||2::Victim||3::Subject-Suspect
## 5                                0::Victim||1::Victim||2::Victim||3::Subject-Suspect
## 6 0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect||5::Subject-Suspect
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         sources
## 1                                                                                                                                                                                                                    http://pittsburgh.cbslocal.com/2013/01/01/4-people-shot-in-mckeesport/||http://www.wtae.com/news/local/allegheny/U-S-Marshals-task-force-arrests-New-Year-s-party-shooting-suspect/17977588||http://www.post-gazette.com/local/south/2013/01/17/Man-arrested-in-New-Year-s-Eve-shooting-in-McKeesport/stories/201301170275
## 2                                                                                                                                                                                                                 http://losangeles.cbslocal.com/2013/01/01/man-killed-3-wounded-at-nye-party-in-hawthorne/||http://latimesblogs.latimes.com/lanow/2013/01/hawthorne-new-year-party-three-killed.html||https://usgunviolence.wordpress.com/2013/01/01/killed-man-hawthorne-ca/||http://www.dailybulletin.com/article/zz/20130105/NEWS/130109127
## 3                                                                                                                                                                                                                                                                                                                                              http://www.morningjournal.com/general-news/20130222/lorain-man-pleads-innocent-to-new-years-murder||http://chronicle.northcoastnow.com/2013/02/14/2-men-indicted-in-new-years-day-lorain-murder/
## 4 http://denver.cbslocal.com/2013/01/06/officer-told-neighbor-standoff-gunman-was-on-meth-binge/||http://www.westword.com/news/sonny-archuleta-triple-murder-in-aurora-guns-purchased-legally-55-57-5900504||http://www.denverpost.com/ci_22322380/aurora-shooter-was-frenetic-talented-neighbor-says||http://www.dailymail.co.uk/news/article-2258008/Sonny-Archuleta-Gunman-left-dead-latest-Aurora-shooting-lost-brother-gun-violence.html||http://www.dailydemocrat.com/20130106/aurora-shootout-killer-was-frenetic-talented-neighbor-says
## 5                                                                                                                                                                                                                                                           http://myfox8.com/2013/01/08/update-mother-shot-14-year-old-son-two-others-before-killing-herself/||http://myfox8.com/2013/01/07/police-respond-to-report-of-triple-shooting-in-greensboro/||http://www.journalnow.com/news/local/article_d4c723e8-5a0f-11e2-a1fa-0019bb30f31a.html
## 6        http://www.kjrh.com/news/local-news/4-found-shot-inside-apartment-in-tulsa||http://www.cbsnews.com/news/tulsa-apartment-murders-update-hearing-scheduled-for-brothers-charged-in-quadruple-killing/||http://www.kjrh.com/news/local-news/hearing-continues-for-fairmont-terrace-quadruple-homicide-suspect-cedric-poore-james-poore||http://www.kjrh.com/news/local-news/hearing-for-quadruple-murder-suspects-continue||http://usnews.nbcnews.com/_news/2013/01/07/16397584-police-four-women-found-dead-in-tulsa-okla-apartment?lite
##   state_house_district state_senate_district perp_age
## 1                   NA                    NA       20
## 2                   62                    35       20
## 3                   56                    13       25
## 4                   40                    28       29
## 5                   62                    27       18
## 6                   72                    11       23

Now let’s make some plots to make sense of our dataset

ggplot(gv, aes(x=n_killed)) + geom_histogram(binwidth=1)

Also would like to see a histogram of ages involved in gun violence incidents.

# Need to remove NA values for a cleaner graph
gv_with_age <- gv %>%
                filter(!is.na(perp_age)) %>%
                mutate(perp_age = as.integer(perp_age))

ggplot(gv_with_age, aes(x=perp_age)) + geom_histogram(binwidth=5)

I’d like to see the locations (via latitude and longitude) mapped out. Using the mapview

# Need to remove NA
gv_with_locs <- gv %>%
                        filter(!is.na(longitude), !is.na(latitude))

mapview(gv_with_locs, xcol="longitude", ycol="latitude", crs = 4326)