Total Violent Crimes Rate of 2010:
I will use 2010 Total violent Crime rate per 10000 people county level data to better understand the violent crime rate throughout the country. By using country level data, we will able to see crime rate in each county that will help official to focus their resources towards high crime country.
Reading My Crime Data:
options(tigris_class = "sf")
US_county <- counties(cb = TRUE)
Crime_2010<-read_csv("C:/Users/Afzal Hossain/Documents/A.Spring 2019/SOC 712/HW/HW10/CrimePHTData2010.csv")
Crime_2010$FIPS<-as.character(Crime_2010$FIPS)
Crime_2010<-Crime_2010 %>%
rename(GEOID=FIPS)%>%
mutate(GEOID = parse_integer(GEOID))
Merging My Data and Map data
crime_comb_data <- US_county %>%
mutate(GEOID = parse_integer(GEOID)) %>%
left_join(Crime_2010, by = 'GEOID')
crime_comb_data$Sate_in<-state.abb[match(crime_comb_data$Sate_Name,state.name)]
Creating subset for Alaska and Hawaii:
US_AK <- crime_comb_data %>%
subset(STATEFP == "02")
US_HI <- crime_comb_data %>%
subset(STATEFP == "15")
Creating Border for Alaska and Hawaii:
Ak_states <- US_AK %>%
aggregate_map(by = "STATEFP")
Hi_states <- US_HI %>%
aggregate_map(by = "STATEFP")
Mainland USA:
crime_comb_data_sub <- crime_comb_data %>%
filter(STATEFP != "02") %>%
filter(STATEFP != "15") %>%
filter(STATEFP != "60") %>%
filter(STATEFP != "66") %>%
filter(STATEFP != "69") %>%
filter(STATEFP != "72") %>%
filter(STATEFP != "78")
Mainland State Border:
us_states <- crime_comb_data_sub %>%
aggregate_map(by = "STATEFP")
Non-spatial Way:
ggplot((crime_comb_data), aes(`Total Violent Crimes Rate`)) + geom_histogram(fill="darksalmon") +xlab("Violent Crimes Rate: 2010")+theme_tufte()+geom_vline(aes(xintercept=mean(crime_comb_data$`Total Violent Crimes Rate`)), color="blue",linetype = "dashed",size = 1)

From above distribution of Total violent crimes of 2010, we can have a general idea about crime rate. We can say that average violent crime rate for counties are less than 250, but there are some county where average violent crime is over 2000.
This distribution give us an over view of the situation, but in order to make a better data driven solution to the problem, we will take advantage of the spatial data where can narrow down the problem to county level.
US Mape of Violent Crime Rate: 2010
tm_shape(crime_comb_data_sub, projection = 2163) + tm_polygons("Total Violent Crimes Rate", midpoint = 1000, border.col = "grey", border.alpha = .5,title="Crimes Rate") +
tm_shape(us_states) + tm_borders(lwd = 1, col = "black", alpha = .5)+tm_style("beaver")+tm_scale_bar(width = 0.18, position = c("right", "top"))+
tm_compass(position = c("right", "bottom"))+tm_layout(title = "Total Violent Crimes Rate: 2010",
title.position = c("center", "top"),
legend.position = c("right", "bottom"),
frame = FALSE,inner.margins = c(0.1, 0.1, 0.05, 0.05),
legend.text.size = 0.6 )

Adding Alaska and Hawaii:
#Mainland
crime_m<-tm_shape(crime_comb_data_sub, projection = 2163) +
tm_polygons("Total Violent Crimes Rate", midpoint = 1000, border.col = "grey",
border.alpha = .5,title="Crimes Rate") +
tm_shape(us_states) + tm_borders(lwd = 1, col = "black", alpha = .5)+tm_style("beaver")+
tm_scale_bar(width = 0.18, position = c("right", "top"))+
tm_compass(position = c("right", "bottom"))+tm_layout(title = "Total Violent Crimes Rate: 2010",
title.position = c("center", "top"),
legend.position = c("right", "bottom"),
frame = FALSE,inner.margins = c(0.1, 0.1, 0.05, 0.05),
legend.text.size = 0.6 )
# Alaska inset
m_AK <- tm_shape(US_AK, projection = 3338) +
tm_polygons("Total Violent Crimes Rate", border.col = "grey",midpoint = 1000, border.alpha = .8 ) +
tm_layout("Alaska", legend.show = FALSE, bg.color = NA, title.size = 0.8, frame = FALSE)+tm_shape(Ak_states)+
tm_borders(lwd = 1, col = "black", alpha = .5)
# Hawaii inset
m_HI <- tm_shape(US_HI, projection = 3759) +
tm_polygons("Total Violent Crimes Rate", border.col = "grey",midpoint=1000, border.alpha = .8) +
tm_layout("Hawaii", legend.show = FALSE, bg.color = NA, title.position = c("LEFT", "BOTTOM"), title.size = 0.8,
frame =FALSE)+tm_shape(Hi_states ) + tm_borders(lwd = 1, col = "black", alpha = .5)
# viewports for Alaska and Hawaii
vp_AK <- viewport(x = 0.15, y = 0.15, width = 0.3, height = 0.3)
vp_HI <- viewport(x = 0.4, y = 0.1, width = 0.2, height = 0.1)
# save map to a image
tmap_mode("plot")
tmap_save(crime_m, "Crime_2010.png", scale = 0.7, width = 6.125, outer.margins = 0,
insets_tm = list(m_AK, m_HI),
insets_vp = list(vp_AK, vp_HI))
Lets Look at Our Combined Map:
knitr::include_graphics("C:/Users/Afzal Hossain/Documents/A.Spring 2019/SOC 712/HW/HW10/Crime_2010.png")

From the map, I can see crime rate in every county in United State and I can easily compare county as well as different state. Louisiana, South Carolina, Texas, Georgia, Florida are the host state for high crime rate county. This state has very little gun control that might be a reason.
New York:
New_York<-crime_comb_data_sub%>%subset(STATEFP==36)
tm_shape(New_York, projection = 2163) + tm_polygons("Total Violent Crimes Rate",palette = "-RdBu", midpoint = 300, border.col = "white", border.alpha = .4,title="Crimes Rate",
legend.hist = T) +tm_text("NAME",size = "AREA")+
tm_scale_bar(width = 0.22, position = c("left", "top")) +
tm_compass()+
tm_borders(lwd = 1, col = "black", alpha = .5)+
tm_layout(frame = F, title = "New York",
title.size = 2,
legend.hist.size = 0.3,
legend.text.size = 0.8,
legend.outside = T)

Since we Live in New York, I am curious about New York Crime. As expected, New York City counties have the highest crime rate out of all counties.Some of the border county like Erie also have very high crime rate.
South Carolina:
SC<-crime_comb_data_sub%>%subset(STATEFP==45)
tm_shape(SC, projection = 2163) + tm_polygons("Total Violent Crimes Rate",midpoint=800, palette = "-RdBu", border.col = "grey", border.alpha = .8,title="Crimes Rate",
legend.hist = T) +tm_text("NAME",size = "AREA")+
tm_borders(lwd = .3, col = "black",alpha = .5)+tm_scale_bar(width = 0.22, position = c("left", "bottom")) +
tm_compass(position = c("right", "top"))+
#tm_bubbles("Total Violent Crimes Rate: Murder Rate", title.size = "% Murder", col = "green")+
tm_borders(lwd = 1, col = "black", alpha = .5)+
tm_layout(frame = F, title = "South Carolina",
legend.position = c("LEFT", "BOTTOM"),
title.size = 2,
title.position = c("LEFT", "BOTTOM"),
legend.hist.size = 0.3,
legend.text.size = 0.8,
legend.outside = T)

Few of the county like Dilon,Marlboro,Allendale and Greenwood thate are causig the problem for South Carolina where crime rate are overe amvrage. This kind of detail was lost in non-spatial data vizulation.
Louisiana:
Louisiana<-crime_comb_data_sub%>%subset(STATEFP==22)
tm_shape(Louisiana, projection = 2163) + tm_polygons("Total Violent Crimes Rate",palette = "-RdBu", midpoint = 1000, border.col = "white", border.alpha = .4,title="Crimes Rate",
legend.hist = T) +tm_text("NAME",size = "AREA")+
tm_scale_bar(width = 0.22, position = c("right", "top")) +
tm_compass(position = c("right", "bottom"))+
tm_borders(lwd = .4, col = "black", alpha = .5)+
tm_bubbles("Total Violent Crimes Rate: Murder Rate", title.size = "# Murder", col = "green")+
tm_layout(frame = F, title = "Louisiana",
title.size = 2,
legend.hist.size = 0.3,
legend.text.size = 0.8,
legend.outside = T,inner.margins = c(0.1, 0.1, 0.02, 0.02)
)

Louisiana’s Catahoula county has the highest crime rate not only in Louisiana, but also in the hole country Where over 28% of the people life under poverty line. It is very interesting to see that, when i added Murder number, Catahoula county has also no Murder. Therefore, most of the crime in that county are assaults. Therefore, spatial data give us more option to present our finding.
Spatial and Non-spatial:
Non-spatial data that is independent of all geometric considerations. For example, a person’s height, weight, and age are non-spatial data because they are independent of the person’s location. Some time people’s weight can be dependent on its locations (Americans tend to be overweight). Non-spatial data are easy to create. On the other hand, spatial data sets are defined as those, which are directly or indirectly referenced to a location on the surface of the earth .In the many discussions on the national policy, a common call is the need for more spatial policymaking. A map can be a helpful instrument in such processes. Roles of mapping activities in interactive policymaking. In my cases, using special data significantly increase the visibility of the crime rate throughout USA County. Non-spatial data would only allow me to create distribution of overall crime rate or for each county, which will get overwhelming very fast which can be a problem if I want to present that to any polici maker.
When CD Is Flase:
Its seems that when I change cb from true to false it take longer where it load unnecessary information and also it create less detail and presentable map compare to cd=TRUE.
t_county <- counties(cb = FALSE)
Crime<-read_csv("C:/Users/Afzal Hossain/Documents/A.Spring 2019/SOC 712/HW/HW10/CrimePHTData2010.csv")
Crime$FIPS<-as.character(Crime$FIPS)
Crime<-Crime %>%
rename(GEOID=FIPS)%>%
mutate(GEOID = parse_integer(GEOID))
f_crime_comb_data <- t_county %>%
mutate(GEOID = parse_integer(GEOID)) %>%
left_join(Crime_2010, by = 'GEOID')
f_crime_comb_data_sub <- f_crime_comb_data %>%
filter(STATEFP != "02") %>%
filter(STATEFP != "15") %>%
filter(STATEFP != "60") %>%
filter(STATEFP != "66") %>%
filter(STATEFP != "69") %>%
filter(STATEFP != "72") %>%
filter(STATEFP != "78")
S_C<-f_crime_comb_data_sub%>%subset(STATEFP==45)
tm_shape(S_C, projection = 2163) + tm_polygons("Total Violent Crimes Rate",midpoint=800, palette = "RdBu", border.col = "grey", border.alpha = .8,title="Crimes Rate"
) +tm_text("NAME",size = "AREA")+
tm_borders(lwd = 1, col = "black", alpha = .5)+
tm_layout(frame = F, title = "South Carolina",
title.size = 1.5,
legend.show=F,
title.position = c("right", "top"),
inner.margins = c(0.1, 0.1, 0.02, 0.02))
