library(tidyverse)
<- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-02-08/airmen.csv')
airmen
# data wrangling--------
<-airmen%>%
df select(name,graduation_date,graduated_from,
pilot_type,
military_hometown_of_record,state,%>%
number_of_aerial_victory_credits)mutate(pilot_type=str_replace_all(pilot_type,"Liaison","Liason"))%>%
filter(!is.na(graduation_date),!is.na(state))%>%
arrange(desc(graduation_date))%>%
mutate(id=row_number())%>%
relocate(id)
# 48 states abbr to be chacked
%>%count(state)
df
%>%mutate(year=lubridate::year(graduation_date))%>%count(year)
df
# map data -----
<-
us_states_df %>%
dfmutate(state_name=usdata::abbr2state(state),
.after=state)%>%
filter(!is.na(state_name)) %>% # 41 us states selected
mutate(state_name = tolower(state_name))
<-
my_states%>%
us_states_dfcount(state_name)%>%
select(-n)%>%unlist()
# US states coordinates
<- map_data("state")
states
<-
my_states_coords%>%
statesfilter(region%in%my_states)%>%
left_join(us_states_df,by=c("region"="state_name"))%>%
mutate(number_of_aerial_victory_credits=ifelse(number_of_aerial_victory_credits==1.5,
2,number_of_aerial_victory_credits))
# World coordinates
<-map_data(map = "world") %>%
worldfilter(!region=="Antarctica")
# alabama $ french morocco
<-data.frame(region=c("french morocco","alabama"),
al_frmolat=c(30.427755,32.318230),
long=c(-9.598107,-86.902298))
# dubois colors -------
<-colorRampPalette(c("#654321","#d2b48c","#ffd700","#ffc0cb","#dc143c","#00aa00","#4682b4"))(5)
states_palette
# fonts---------
library(extrafont)
library(showtext)
::showtext_auto()
showtext::showtext_opts(dpi=320)
showtextlibrary(sysfonts)
#font_families_google()
font_add_google(name="Barlow Condensed",family="dubois")
# make the map plots ---------------------
<-
world_west ggplot() +
geom_polygon(data=world,aes(x=long,y=lat,group=group),
fill="wheat2",color="#654321") +
geom_polygon(data = states,
aes(x = long, y = lat, group = group),
fill="wheat2",color="#654321",size=0.1) +
geom_polygon(data = subset(my_states_coords,number_of_aerial_victory_credits==1),
aes(x = long, y = lat, group = group,
fill=factor(number_of_aerial_victory_credits)),
color="#654321",size=0.05) +
geom_polygon(data = subset(my_states_coords,number_of_aerial_victory_credits==2),
aes(x = long, y = lat, group = group,
fill=factor(number_of_aerial_victory_credits)),
color="#654321",size=0.05) +
geom_polygon(data = subset(my_states_coords,number_of_aerial_victory_credits==3),
aes(x = long, y = lat, group = group,
fill=factor(number_of_aerial_victory_credits)),
color="#654321",size=0.05)+
geom_polygon(data = subset(my_states_coords,number_of_aerial_victory_credits==4),
aes(x = long, y = lat, group = group,
fill=factor(number_of_aerial_victory_credits)),
color="#654321",size=0.05)+
geom_point(data=al_frmo,aes(x=long,y=lat),color="red")+
scale_fill_manual(values=states_palette)+
coord_map("ortho", orientation = c(3.849945, -103.525750, 0)) +
labs(title=" \n \n ",
subtile=" \n \n ",
x="",y="",fill="Aerial victories") +
theme_void() +
theme(legend.position = c(0.5,1.2),
legend.direction = "horizontal")
<-
world_est ggplot() +
geom_polygon(data=world,aes(x=long,y=lat,group=group),
fill="wheat2",color="#654321") +
geom_polygon(data = states,
aes(x = long, y = lat, group = group),
fill="wheat2",color="#654321",size=0.1) +
geom_polygon(data = subset(my_states_coords,number_of_aerial_victory_credits==1),
aes(x = long, y = lat, group = group,
fill=factor(number_of_aerial_victory_credits)),
color="#654321",size=0.05)+
geom_polygon(data = subset(my_states_coords,number_of_aerial_victory_credits==2),
aes(x = long, y = lat, group = group,
fill=factor(number_of_aerial_victory_credits)),
color="#654321",size=0.05)+
geom_polygon(data = subset(my_states_coords,number_of_aerial_victory_credits==3),
aes(x = long, y = lat, group = group,
fill=factor(number_of_aerial_victory_credits)),
color="#654321",size=0.05)+
geom_polygon(data = subset(my_states_coords,number_of_aerial_victory_credits==4),
aes(x = long, y = lat, group = group,
fill=factor(number_of_aerial_victory_credits)),
color="#654321",size=0.05) +
geom_point(data=al_frmo,aes(x=long,y=lat),color="red")+
scale_fill_manual(values=states_palette)+
coord_map("ortho", orientation = c(10.050474, 55.740732,0)) + #9.982182, 49.595135, 0)) +
labs(title=" \n \n ",subtile=" \n \n ",x="",y="",color="") +
theme_void() +
theme(legend.position = "none")
# draw curved text-----------------------
<-2*pi
t
<-
df_text_left data.frame(x = cos(t),
y = sin(t),
xend = cos(t + 1.8),
yend = sin(t + 1.8))
<-ggplot(df_text_left) +
p ::geom_textcurve(aes(x, y, xend = xend, yend = yend),
geomtextpathlabel = c("Afican-American pilots victory"),
curvature = 0.2, vjust = 1) +
coord_equal(xlim = c(-1.1, 1.1), ylim = c(-1.1, 1.2))
<-ggplot(df_text_left) +
q ::geom_textcurve(aes(-x, y, xend =- xend, yend = yend),
geomtextpathlabel = c("Army Air Force during WWII"),
curvature = -0.2, vjust = -0) +
coord_equal(xlim = c(-1.1, 1.1), ylim = c(-1.1, 1.2))
library(patchwork)
<-(p+q)
text_curved <- text_curved & theme_void()
text_curved
# draw circle and a curve-----------
<- grid::circleGrob(gp = grid::gpar(fill = "#baa388",color="#654321",size=0.5))
g
# final touches----------
library(cowplot)
<-ggdraw()+
final_plotdraw_image("duboisbg.jpeg",
scale = 1.6)+
draw_grob(g, scale=0.542,x=-0.223,y=-0.1) +
draw_grob(g, scale=0.542,x=0.229,y=-0.1) +
draw_plot(world_west,scale=0.6,x=-0.229,y=-0.07)+
draw_plot(world_est,scale=0.6,x=0.229,y=-0.07) +
draw_image("https://tile.loc.gov/storage-services/service/pnp/ppmsca/33800/33863r.jpg",
scale=0.3,x=0.4,y=0.35) +
draw_label("#30DayMapChallenge 2022 Day 20: My favourite\nTuskegee Airmen: Aerial Victories\nAir Force Historical Research Agency\nGraduation 1942 - 1948",
fontfamily="dubois",color="#291c10",
x=0.5,y=0.9,size=25,fontface = "bold")+
draw_label("DataSource: Tuskegee Airmen | Viz @fgazzelloni \n #DuBoisChallenge | #TidyTuesday 2022/06",
fontfamily="dubois",color="#291c10",
x=0.5,y=0.12,size=14,fontface = "bold")+
draw_plot(text_curved,x=0,y=0.05,scale = 0.5)+
draw_label("This paper focus on their aerial victory credits.
The most famous of the 332d Fighter Group commanders was Col.Benjamin O. Davis,Jr.
The 99th Fighter Squadron deployed from Tuskegee, Alabama, to French Morocco in April 1943.",
fontfamily="dubois",color="#291c10",
x=0.5,y=0.04,size=14,fontface = "bold")
# save the plot--------
::agg_png("day20_my_favorite.png",
raggres = 320, width = 12, height = 10, units = "in")
final_plot
dev.off()
TidyTuesday week 6 2022
original Dubois collection:
- https://www.loc.gov/collections/african-american-photographs-1900-paris-exposition/?sb=shelf-id_desc&sp=1&st=grid
- https://github.com/ajstarks/dubois-data-portraits/blob/master/plate01/georgia-negro.dsh