Lets first add needed libraries and the data file we will be working with.

library(knitr)
## Warning: package 'knitr' was built under R version 3.5.3
library(rmarkdown)
library(prettydoc)
## Warning: package 'prettydoc' was built under R version 3.5.3
knitr::opts_chunk$set(echo = TRUE)
library(readr)
## Warning: package 'readr' was built under R version 3.5.3
Gun_Violence <- read_csv("gun-violence-data_01-2013_03-2018.csv", 
    na = "null")
## Parsed with column specification:
## cols(
##   .default = col_character(),
##   incident_id = col_double(),
##   date = col_date(format = ""),
##   n_killed = col_double(),
##   n_injured = col_double(),
##   incident_url_fields_missing = col_logical(),
##   congressional_district = col_double(),
##   latitude = col_double(),
##   longitude = col_double(),
##   n_guns_involved = col_double(),
##   state_house_district = col_double(),
##   state_senate_district = col_double()
## )
## See spec(...) for full column specifications.

Before reading in the data I noticed alot of missing data so made sure to read in with NA = null to help eliminate unusable data.

Below is the structure of the Gun Violence data I just Read into R:

str(Gun_Violence)
## Classes 'spec_tbl_df', 'tbl_df', 'tbl' and 'data.frame': 239677 obs. of  29 variables:
##  $ incident_id                : num  461105 460726 478855 478925 478959 ...
##  $ date                       : Date, format: "2013-01-01" "2013-01-01" ...
##  $ state                      : chr  "Pennsylvania" "California" "Ohio" "Colorado" ...
##  $ city_or_county             : chr  "Mckeesport" "Hawthorne" "Lorain" "Aurora" ...
##  $ address                    : chr  "1506 Versailles Avenue and Coursin Street" "13500 block of Cerise Avenue" "1776 East 28th Street" "16000 block of East Ithaca Place" ...
##  $ n_killed                   : num  0 1 1 4 2 4 5 0 0 1 ...
##  $ n_injured                  : num  4 3 3 0 2 0 0 5 4 6 ...
##  $ incident_url               : chr  "http://www.gunviolencearchive.org/incident/461105" "http://www.gunviolencearchive.org/incident/460726" "http://www.gunviolencearchive.org/incident/478855" "http://www.gunviolencearchive.org/incident/478925" ...
##  $ source_url                 : chr  "http://www.post-gazette.com/local/south/2013/01/17/Man-arrested-in-New-Year-s-Eve-shooting-in-McKeesport/stories/201301170275" "http://www.dailybulletin.com/article/zz/20130105/NEWS/130109127" "http://chronicle.northcoastnow.com/2013/02/14/2-men-indicted-in-new-years-day-lorain-murder/" "http://www.dailydemocrat.com/20130106/aurora-shootout-killer-was-frenetic-talented-neighbor-says" ...
##  $ incident_url_fields_missing: logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
##  $ congressional_district     : num  14 43 9 6 6 1 1 2 9 7 ...
##  $ gun_stolen                 : chr  "" "" "0::Unknown||1::Unknown" "" ...
##  $ gun_type                   : chr  "" "" "0::Unknown||1::Unknown" "" ...
##  $ incident_characteristics   : chr  "Shot - Wounded/Injured||Mass Shooting (4+ victims injured or killed excluding the subject/suspect/perpetrator, "| __truncated__ "Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Mass Shooting (4+ victims injured or killed "| __truncated__ "Shot - Wounded/Injured||Shot - Dead (murder, accidental, suicide)||Shots Fired - No Injuries||Bar/club incident"| __truncated__ "Shot - Dead (murder, accidental, suicide)||Officer Involved Incident||Officer Involved Shooting - subject/suspe"| __truncated__ ...
##  $ latitude                   : num  40.3 33.9 41.4 39.7 36.1 ...
##  $ location_description       : chr  "" "" "Cotton Club" "" ...
##  $ longitude                  : num  -79.9 -118.3 -82.1 -104.8 -80 ...
##  $ n_guns_involved            : num  NA NA 2 NA 2 NA 2 NA NA NA ...
##  $ notes                      : chr  "Julian Sims under investigation: Four Shot and Injured" "Four Shot; One Killed; Unidentified shooter in getaway car" "" "" ...
##  $ participant_age            : chr  "0::20" "0::20" "0::25||1::31||2::33||3::34||4::33" "0::29||1::33||2::56||3::33" ...
##  $ participant_age_group      : chr  "0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+" "0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+" "0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+||4::Adult 18+" "0::Adult 18+||1::Adult 18+||2::Adult 18+||3::Adult 18+" ...
##  $ participant_gender         : chr  "0::Male||1::Male||3::Male||4::Female" "0::Male" "0::Male||1::Male||2::Male||3::Male||4::Male" "0::Female||1::Male||2::Male||3::Male" ...
##  $ participant_name           : chr  "0::Julian Sims" "0::Bernard Gillis" "0::Damien Bell||1::Desmen Noble||2::Herman Seagers||3::Ladd Tate Sr||4::Tallis Moore" "0::Stacie Philbrook||1::Christopher Ratliffe||2::Anthony Ticali||3::Sonny Archuleta" ...
##  $ participant_relationship   : chr  "" "" "" "" ...
##  $ participant_status         : chr  "0::Arrested||1::Injured||2::Injured||3::Injured||4::Injured" "0::Killed||1::Injured||2::Injured||3::Injured" "0::Injured, Unharmed, Arrested||1::Unharmed, Arrested||2::Killed||3::Injured||4::Injured" "0::Killed||1::Killed||2::Killed||3::Killed" ...
##  $ participant_type           : chr  "0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect" "0::Victim||1::Victim||2::Victim||3::Victim||4::Subject-Suspect" "0::Subject-Suspect||1::Subject-Suspect||2::Victim||3::Victim||4::Victim" "0::Victim||1::Victim||2::Victim||3::Subject-Suspect" ...
##  $ sources                    : chr  "http://pittsburgh.cbslocal.com/2013/01/01/4-people-shot-in-mckeesport/||http://www.wtae.com/news/local/alleghen"| __truncated__ "http://losangeles.cbslocal.com/2013/01/01/man-killed-3-wounded-at-nye-party-in-hawthorne/||http://latimesblogs."| __truncated__ "http://www.morningjournal.com/general-news/20130222/lorain-man-pleads-innocent-to-new-years-murder||http://chro"| __truncated__ "http://denver.cbslocal.com/2013/01/06/officer-told-neighbor-standoff-gunman-was-on-meth-binge/||http://www.west"| __truncated__ ...
##  $ state_house_district       : num  NA 62 56 40 62 72 10 93 11 NA ...
##  $ state_senate_district      : num  NA 35 13 28 27 11 14 5 7 44 ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   incident_id = col_double(),
##   ..   date = col_date(format = ""),
##   ..   state = col_character(),
##   ..   city_or_county = col_character(),
##   ..   address = col_character(),
##   ..   n_killed = col_double(),
##   ..   n_injured = col_double(),
##   ..   incident_url = col_character(),
##   ..   source_url = col_character(),
##   ..   incident_url_fields_missing = col_logical(),
##   ..   congressional_district = col_double(),
##   ..   gun_stolen = col_character(),
##   ..   gun_type = col_character(),
##   ..   incident_characteristics = col_character(),
##   ..   latitude = col_double(),
##   ..   location_description = col_character(),
##   ..   longitude = col_double(),
##   ..   n_guns_involved = col_double(),
##   ..   notes = col_character(),
##   ..   participant_age = col_character(),
##   ..   participant_age_group = col_character(),
##   ..   participant_gender = col_character(),
##   ..   participant_name = col_character(),
##   ..   participant_relationship = col_character(),
##   ..   participant_status = col_character(),
##   ..   participant_type = col_character(),
##   ..   sources = col_character(),
##   ..   state_house_district = col_double(),
##   ..   state_senate_district = col_double()
##   .. )

The Gun Vilolence dataset provides plenty of information in regard to the incident characteristics and the exact location of the gun violence using longitude and latitude. We will be using the address, location description, gun-type, and incident characteristics. In order to do this it will require some data cleaning utilizing the paste function. The data could use further cleaning if I was planning to run analysis, but for my purposes we won’t need to do much cleaining.

Data<-paste(sep = " ", Gun_Violence$address, Gun_Violence$location_description, Gun_Violence$gun_type, Gun_Violence$incident_characteristics)

The purpose of using the paste function is to combine 4 different columns for the purpose of my marker discriptions.

Before proceeding I needed to open the leaflet library to access the code below.

library(leaflet)

To help with all the points on the map I used the below code so I didn’t have to plot every marker. This code allows you to zoom in to each cluster which then separates allowing you to see each marker individually. When you click on the marker The incident characteristics pops up on the marker. Click on any blue marker to see the incident characteristics of each gun violence record.

Gun_Violence %>% leaflet() %>% addTiles() %>% addPopups(lat=29.5850369, lng=-98.6182212, '<b>Just made this!</b>, no really! Just made this here in Cambells Class at UTSA! ') %>% addCircleMarkers (popup=Data,clusterOptions=markerClusterOptions())
## Assuming "longitude" and "latitude" are longitude and latitude, respectively
## Warning in validateCoords(lng, lat, funcName): Data contains 7923 rows with
## either missing or invalid lat/lon values and will be ignored

Above you can see with simple code I created something that looks like only a professional could. I even made a popup showing the exactlocation I made this utilzing latitude and longtitude I got by using my cell phone. I enjoyed this data set because you can get alot of information just off the map itself and could do alot of exploratory analysis with it. The power of R really shines with its libraries such as the leaflet library. Above you have an interactive map and it only took a couple lines of code.