#make SF object for south america and left join crime data by country namesa_map <-ne_countries(continent ='south america', returnclass ='sf')sa_map <-left_join(sa_map, southamerica_crime, by ="sovereignt") |>select(name, pop_est, Country, sovereignt, Year, Series, Value, geometry)# see if you can wrap by series, and only plot the value for each individual seriesp1 <-ggplot(data = southamerica_crime, mapping =aes(x = Year, y = Value)) +geom_smooth() +scale_y_log10(labels = comma) +facet_wrap(~sovereignt) +labs(Title ='Total Crime Rates Per South American Nation',caption ="Data sourced from: https://data.un.org/")p1 +enter_fade() +exit_recolor()
#join in cartel datadrug_clean <- drug_data |>count(Countryofseizure)drug_clean <-mutate(drug_clean, Countryofseizure =case_when( Countryofseizure =='Bolivia (Plurinational State of)'~'Bolivia', Countryofseizure =='Venezuela (Bolivarian Republic of)'~'Venezuela', Countryofseizure =='Argentina'~'Argentina', Countryofseizure =='Colombia'~'Colombia', Countryofseizure =='Peru'~'Peru', Countryofseizure =='Paraguay'~'Paraguay', Countryofseizure =='Chile'~'Chile', Countryofseizure =='Brazil'~'Brazil', Countryofseizure =='French Guiana'~'French Guiana', Countryofseizure =='Uruguay'~'Uruguay', Countryofseizure =='Ecuador'~'Ecuador', Countryofseizure =='Guyana'~'Guyana', Countryofseizure =='Suriname'~'Suriname', Countryofseizure =='Belize'~'Belize', Countryofseizure =='Falkland Islands'~'Falkland Islands'))colnames(drug_clean)[1] ="sovereignt"final_map <-left_join(sa_map, drug_clean, by ='sovereignt')#make leaflet with all the data used so far layered neatly pal <-colorNumeric(palette =c('grey', 'pink', 'red'),domain = final_map$n)s <-leaflet(data = final_map) |>addProviderTiles("Thunderforest.OpenCycleMap") |>addPolygons(stroke =FALSE,smoothFactor =0.2,color =~pal(n),opacity =0.35,fillOpacity =0.25) |>addLegend( colors ="White",labels ="Drug busts are concentrated in Colombia and Bolivia",title ="Drugs and Violence in South America",opacity =0.5,position ="bottomleft")s