Assignment
In this assignment, I am using US hate crime data from fivethirtyeight website, compare and visualize the hate crime and how much share contributed on some factors like unemployment, with high school degree and non-citizen
Packages Used
usmap - US map graphical representation
ggplot2 - Utilized the capability of ggplot along with usmap package
dplyr - some data manipulation like selecting columns and mutating data values when there is ‘NA’ value
library(tidyverse)
library(kableExtra)
library(usmap)
library(ggplot2)
hate_crimes <- read.csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/hate-crimes/hate_crimes.csv", sep = ",", stringsAsFactors = F)
per_100k_splc <- hate_crimes %>% select(state,avg_hatecrimes_per_100k_fbi,share_non_citizen,share_unemployed_seasonal,share_population_with_high_school_degree) %>% mutate(share_non_citizen = replace_na(share_non_citizen, 0)) %>% mutate(avg_hatecrimes_per_100k_fbi = replace_na(avg_hatecrimes_per_100k_fbi, 0))
kable(data.frame(per_100k_splc)) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>%
row_spec(0, bold = T, color = "white", background = "#ea7872") %>%
scroll_box(width = "100%", height = "300px")
|
state
|
avg_hatecrimes_per_100k_fbi
|
share_non_citizen
|
share_unemployed_seasonal
|
share_population_with_high_school_degree
|
|
Alabama
|
1.8064105
|
0.02
|
0.060
|
0.821
|
|
Alaska
|
1.6567001
|
0.04
|
0.064
|
0.914
|
|
Arizona
|
3.4139280
|
0.10
|
0.063
|
0.842
|
|
Arkansas
|
0.8692089
|
0.04
|
0.052
|
0.824
|
|
California
|
2.3979859
|
0.13
|
0.059
|
0.806
|
|
Colorado
|
2.8046888
|
0.06
|
0.040
|
0.893
|
|
Connecticut
|
3.7727015
|
0.06
|
0.052
|
0.886
|
|
Delaware
|
1.4699796
|
0.05
|
0.049
|
0.874
|
|
District of Columbia
|
10.9534797
|
0.11
|
0.067
|
0.871
|
|
Florida
|
0.6980703
|
0.09
|
0.052
|
0.853
|
|
Georgia
|
0.4120118
|
0.08
|
0.058
|
0.839
|
|
Hawaii
|
0.0000000
|
0.08
|
0.034
|
0.904
|
|
Idaho
|
1.8913305
|
0.04
|
0.042
|
0.884
|
|
Illinois
|
1.0440158
|
0.07
|
0.054
|
0.864
|
|
Indiana
|
1.7573566
|
0.03
|
0.044
|
0.866
|
|
Iowa
|
0.5613956
|
0.03
|
0.036
|
0.914
|
|
Kansas
|
2.1439867
|
0.04
|
0.044
|
0.897
|
|
Kentucky
|
4.2078896
|
0.03
|
0.050
|
0.817
|
|
Louisiana
|
1.3411696
|
0.02
|
0.060
|
0.822
|
|
Maine
|
2.6266109
|
0.00
|
0.044
|
0.902
|
|
Maryland
|
1.3248395
|
0.08
|
0.051
|
0.890
|
|
Massachusetts
|
4.8018993
|
0.09
|
0.046
|
0.890
|
|
Michigan
|
3.2004423
|
0.04
|
0.050
|
0.879
|
|
Minnesota
|
3.6124118
|
0.05
|
0.038
|
0.915
|
|
Mississippi
|
0.6227460
|
0.00
|
0.061
|
0.804
|
|
Missouri
|
1.9089550
|
0.02
|
0.053
|
0.868
|
|
Montana
|
2.9549594
|
0.01
|
0.041
|
0.908
|
|
Nebraska
|
2.6862484
|
0.05
|
0.029
|
0.898
|
|
Nevada
|
2.1139902
|
0.10
|
0.067
|
0.839
|
|
New Hampshire
|
2.1059886
|
0.03
|
0.034
|
0.913
|
|
New Jersey
|
4.4132026
|
0.11
|
0.056
|
0.874
|
|
New Mexico
|
1.8864352
|
0.06
|
0.068
|
0.828
|
|
New York
|
3.1021643
|
0.10
|
0.051
|
0.847
|
|
North Carolina
|
1.2626798
|
0.05
|
0.058
|
0.843
|
|
North Dakota
|
4.7410699
|
0.03
|
0.028
|
0.901
|
|
Ohio
|
3.2404204
|
0.03
|
0.045
|
0.876
|
|
Oklahoma
|
1.0816721
|
0.04
|
0.044
|
0.856
|
|
Oregon
|
3.3948861
|
0.07
|
0.062
|
0.891
|
|
Pennsylvania
|
0.4309276
|
0.03
|
0.053
|
0.879
|
|
Rhode Island
|
1.2825718
|
0.08
|
0.054
|
0.847
|
|
South Carolina
|
1.9370828
|
0.03
|
0.057
|
0.836
|
|
South Dakota
|
3.3017371
|
0.00
|
0.035
|
0.899
|
|
Tennessee
|
3.1360512
|
0.04
|
0.057
|
0.831
|
|
Texas
|
0.7527683
|
0.11
|
0.042
|
0.799
|
|
Utah
|
2.3840650
|
0.04
|
0.036
|
0.904
|
|
Vermont
|
1.9030814
|
0.01
|
0.037
|
0.910
|
|
Virginia
|
1.7247546
|
0.06
|
0.043
|
0.866
|
|
Washington
|
3.8177403
|
0.08
|
0.052
|
0.897
|
|
West Virginia
|
2.0370536
|
0.01
|
0.073
|
0.828
|
|
Wisconsin
|
1.1219447
|
0.03
|
0.043
|
0.898
|
|
Wyoming
|
0.2669408
|
0.02
|
0.040
|
0.918
|
Visualization
us_crime <- plot_usmap(data = per_100k_splc, values = "avg_hatecrimes_per_100k_fbi", lines = "red",labels = TRUE) +
scale_fill_continuous(
low = "white", high = "red", name = "US Hate Crimes"
) + theme(legend.position = "right", plot.title = element_text(hjust = 0.5)) + labs(title = "US Hate Crimes")
non_citizen <- plot_usmap(data = per_100k_splc, values = "share_non_citizen", lines = "red",labels = TRUE) +
scale_fill_continuous(
low = "white", high = "red", name = "share_non_citizen"
) + theme(legend.position = "right", plot.title = element_text(hjust = 0.5)) + labs(title = "Non Citizen Share of hate crime")
unemployment <- plot_usmap(data = per_100k_splc, values = "share_unemployed_seasonal", lines = "red",labels = TRUE) +
scale_fill_continuous(
low = "white", high = "red", name = "share_unemployed_seasonal"
) + theme(legend.position = "right", plot.title = element_text(hjust = 0.5)) + labs(title = "Unemployment Share of hate crime")
high_school_degree <- plot_usmap(data = per_100k_splc, values = "share_population_with_high_school_degree", lines = "red",labels = TRUE) +
scale_fill_continuous(
low = "white", high = "red", name = "with School Degree"
) + theme(legend.position = "right", plot.title = element_text(hjust = 0.5)) + labs(title = "With School Degree Share of hate crime")
us_crime



