Loading Libraries & Data
library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(magrittr)
library(tidyverse)
## -- Attaching packages ---------------------------------------------------- tidyverse 1.2.1 --
## v tibble 1.4.2 v purrr 0.2.4
## v tidyr 0.7.2 v stringr 1.2.0
## v tibble 1.4.2 v forcats 0.2.0
## -- Conflicts ------------------------------------------------------- tidyverse_conflicts() --
## x tidyr::extract() masks magrittr::extract()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## x purrr::set_names() masks magrittr::set_names()
CRIME_DATA <- read_csv("C:/Users/Meghan/Documents/CRIME DATA.csv")
## Parsed with column specification:
## cols(
## .default = col_integer(),
## Geo_Name = col_character(),
## Geo_QName = col_character(),
## SE_A002_001 = col_double(),
## SE_T011_001 = col_double(),
## SE_T011_002 = col_double(),
## SE_T011_003 = col_double(),
## SE_T011_004 = col_double(),
## SE_T011_005 = col_double(),
## SE_T011_006 = col_double(),
## SE_T011_007 = col_double(),
## SE_T011_008 = col_double(),
## SE_T011_009 = col_double(),
## SE_T011_010 = col_double(),
## SE_T011_011 = col_double(),
## SE_T011_012 = col_double(),
## SE_T011_013 = col_double(),
## SE_T011_014 = col_double(),
## SE_T011_015 = col_double(),
## SE_T011_016 = col_double(),
## SE_T011_017 = col_double()
## # ... with 106 more columns
## )
## See spec(...) for full column specifications.
Selecting Variables to Keep
CRIME_DATA <- select(CRIME_DATA, Geo_FIPS, Geo_Name, Geo_QName, SE_T001_001, SE_T002_001, SE_A001_001, SE_T010_001)
Renaming Variables
- Total Crimes
- Violet and Property Crimes
- Arson
- Arrests
CRIME_DATA <- rename(CRIME_DATA,
"var.FIPS" = Geo_FIPS,
"State" = Geo_Name,
"State2" = Geo_QName,
"TotalCrimes" = SE_T001_001,
"ViolentandPropertyCrimes" = SE_T002_001,
"Arson" = SE_A001_001,
"Arrests" = SE_T010_001)
Mean Summary of Crimes in Different States
summarize (CRIME_DATA, meanTotalCrimes = mean(ViolentandPropertyCrimes, na.rm = TRUE))
summarize (CRIME_DATA, meanTotalCrimes = mean(Arson, na.rm = TRUE))
summarize (CRIME_DATA, meanTotalCrimes = mean(Arrests, na.rm = TRUE))
Running another head to check out the renamed and cleaned data
head(CRIME_DATA)
Bar Charts of Different Crimes For Each State
ggplot(data=CRIME_DATA)+
geom_col(aes(x=State,y=TotalCrimes))+
coord_flip()

ggplot(data=CRIME_DATA)+
geom_col(aes(x=State,y=TotalCrimes))+
coord_flip()

ggplot(data=CRIME_DATA)+
geom_col(aes(x=State,y=Arson))+
coord_flip()

ggplot(data=CRIME_DATA)+
geom_col(aes(x=State,y=Arrests))+
coord_flip()
