library(tidyverse)
library(afriadmin)
library(afrihealthsites)
library(afrilearndata)
library(tmap)
::afcountries
afriadmin#afriadmin::afcountrynames(afcountries$name)
<- afriadmin::afcountries$name
countries
::africapitals
afrilearndata::afrihighway
afrilearndata::afripop2000
afrilearndata::afripop2020
afrilearndata::africountries
afrilearndata::sf_af_gadm0
afriadmin::sf_healthsites_af afrihealthsites
::st_crs(africountries)=st_crs(4326)
sf::st_crs(afrihighway)=st_crs(4326)
sf::st_crs(africapitals)=st_crs(4326) sf
tmap_mode("plot")
<- tmap::tm_shape(africountries) +
pop_00 tm_polygons(col = "#42ecf5") +
tm_shape(afripop2000)+
tm_raster(title="Population density",
palette = rev(viridisLite::inferno(5)),
breaks = c(0,2,20,200,2000,25000)) +
tm_shape(afrihighway) +
tm_lines(col="#f5b342") +
tm_shape(africountries)+
tm_borders() +
tm_text(text ="iso_a3",
fontface = "bold",
col="midnightblue",
size = "pop_est",
title.size = "",
legend.size.show = TRUE,
sizes.legend.text = "Pop"
+
)
tm_shape(africapitals) +
tm_symbols(col="midnightblue",scale = 0.2) +
tm_layout(title="2000",
title.position = c(0.8,0.9),
legend.title.size = 1,
legend.text.size = 0.5,
legend.position = c("left","bottom"),
legend.bg.color = NA
)
<- tmap::tm_shape(africountries) +
pop_20 tm_polygons(col = "#42ecf5") +
tm_shape(afripop2020)+
tm_raster(title="Population density",
palette = rev(viridisLite::inferno(5)),
breaks = c(0,2,20,200,2000,25000)) +
tm_shape(afrihighway) +
tm_lines(col="#f5b342") +
tm_shape(africountries)+
tm_borders() +
tm_text(text ="iso_a3",
fontface = "bold",
col="midnightblue",
size = "pop_est",
title.size = "",
legend.size.show = TRUE,
sizes.legend.text = "Pop"
+
)
tm_shape(africapitals) +
tm_symbols(col="midnightblue",scale = 0.2) +
tm_layout(title="2020",
title.position = c(0.8,0.9),
legend.title.size = 1,
legend.text.size = 0.5,
legend.position = c("left","bottom"),
legend.bg.color = NA
)
<-tmap_arrange(pop_00,pop_20,ncol = 2) my_raster
# save final plot
::agg_png(here::here("day10_raster/raster.png"),
raggres = 320, width = 8, height = 6, units = "in")
my_rasterdev.off()
library(showtext)
library(extrafont)
::font_info_google("Josefin Sans")
sysfonts#fonts()
#loadfonts()
font_add_google("Josefin Sans","josefin")
showtext_opts(dpi = 320)
showtext_auto(enable = T)
# final touches
library(cowplot)
library(magick)
<- magick::image_read(here::here("day10_raster/raster.png"))
raster_image
<- grid::circleGrob(gp = grid::gpar(fill = NA,color="black"))
g
<- cowplot::ggdraw()+
final draw_image(raster_image,x = 0.1, y = 0,width = 0.7)+
draw_label(label="Africa",x=0.3,y=0.2,fontfamily="josefin",size=40) +
draw_label(label="density increased\nin some areas\nmore than others",x=0.52,y=0.35,fontfamily="josefin",size=8) +
draw_label(label="Population density transition 2000-2020", x=0.45, y=0.95, size=30, fontfamily="josefin") +
draw_line(x = c(0.52, 0.5),y = c(0.38, 0.48),color = "black", size = 0.2)+
draw_line(x = c(0.52, 0.6),y = c(0.38, 0.5),color = "black", size = 0.2)+
draw_text("Datasource: afrilearndata\n#TidyTuesdat week46 and #30DayMapChallenge day10 Raster\nInfographics: Federica Gazzelloni",x=0.5,y=0.05,family="josefin",size=11)+
draw_grob(g, scale = 0.2,x = 0,y = 0.03)
# save final plot
::agg_png(here::here("day10_raster/raster2.png"),
raggres = 320, width = 12, height = 8, units = "in")
finaldev.off()