library(tidyverse)
<- tidytuesdayR::tt_load(2021, week = 30)
tuesdata
<- tuesdata$drought
drought
<- c("D0"="Abnormally Dry",
intensity_impacts"D1"="Moderate Drought",
"D2"="Severe Drought",
"D3"= "Extreme Drought",
"D4"="Exceptional Drought")
<- drought %>%
drought_short ::select(-map_date,-stat_fmt) %>%
dplyrfilter(!drought_lvl=="None",!area_pct==0)
Overview
This US Drought map
shows available values by County - Jan to July 2021, data is from TidyTuesday
2021 week 30.
library(sf)
library(raster)
library(spData)
library(spDataLarge)
library(maps)
library(viridis)
library(ggthemes)
library(zipcodeR)
::download_zip_data()
zipcodeR
<- zipcodeR::search_state(drought_short$state_abb)%>%
geo_codes::select(major_city,county,state,lat,lng,
dplyr
population,population_density,
land_area_in_sqmi,water_area_in_sqmi,
housing_units,occupied_housing_units,%>%
median_home_value,median_household_income) drop_na()
<-geo_codes%>%
my_geo_codes_df::select(state,lat,lng) dplyr
<- drought_short %>%
drought_short_map arrange(valid_start)%>%
mutate(year=lubridate::year(valid_start),
month=lubridate::month(valid_start))%>%
filter(str_detect(valid_start,"2021")) %>%
#filter(month==c(1,2,3)) %>%
group_by(month,state_abb,drought_lvl) %>%
summarize(med_area_pct=round(median(area_pct),2))%>%
ungroup() %>%
filter(!med_area_pct==0) %>%
left_join(my_geo_codes_df,by=c("state_abb"="state")) %>%
mutate(month = month.name[month])
<- drought_short_map%>%count(month,sort=T)%>%
my_df ::select(-n)%>%
dplyrmutate(month_id=row_number())%>%
inner_join(drought_short_map,by="month")
library(extrafont)
#loadfonts()
#fonts()
<- "Roboto Condensed"
droughts_family
library(gganimate)
library(cartography)
<-c("red", "orangered", "firebrick1", "brown3", "firebrick") red.pal
<- map_data("county")
us_county_map <- map_data("state")
us_state_map
ggplot() +
geom_point(data=subset(my_df,lat>25&lat<50),
aes(x=lng,y=lat,color=factor(drought_lvl)),
alpha=0.5,size=.4) +
geom_polygon(data=us_county_map,aes(x=long,y=lat,group = group),
fill=NA,color = "darkred",size=0.2) +
geom_polygon(data=us_state_map,aes(x=long,y=lat,group = group),
fill=NA,color = "red",size=0.4) +
scale_color_manual(labels = intensity_impacts,
values=red.pal) +
coord_sf()+
::theme_map() +
ggthemestheme(legend.position = "none",
legend.title = element_text(family = droughts_family),
legend.text = element_text(size=8,family =droughts_family),
legend.background = element_blank(),
legend.box.background = element_blank(),
legend.key = element_blank(),
strip.background = element_blank(),
strip.text = element_text(family = droughts_family),
plot.title =element_text(size=25,face="bold",family =droughts_family,color="black"),
plot.subtitle =element_text(size=12,face="bold",family =droughts_family),
plot.caption =element_text(size=9,family =droughts_family,hjust = 0),
plot.caption.position = "panel",
plot.title.position = "panel") +
# gganimate specific bits:
labs(title="US Drought variation - Month: {closest_state}",
subtitle="",
caption="US Drought map: available values by County - Jan to July 2021\n
#30DayMapChallenge day6-red - graphic: Federica Gazzelloni")+
transition_states(month) +
ease_aes('linear')
# Save at gif:
anim_save("drought_red.gif")