library(tidyverse)
<- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-09-20/HydroWASTE_v10.csv')
HydroWASTE_v10
%>%names HydroWASTE_v10
%>%DataExplorer::profile_missing() HydroWASTE_v10
# HydroWASTE_v10%>%View()
<- HydroWASTE_v10%>%
df ::clean_names()%>%
janitorcount(country,lat_wwtp,lon_wwtp,source,
qual_loc,qual_pop,qual_waste,qual_level,qual_cap)
# source: https://stackoverflow.com/questions/68278789/how-to-rotate-world-map-using-mollweide-projection-with-sf-rnaturalearth-ggplot
library(rnaturalearth)
library(rnaturalearthdata)
library(sf)
<- st_crs("+proj=moll +x_0=0 +y_0=0 +lat_0=0 +lon_0=133")
target_crs
<- ne_countries(scale = "medium", returnclass = "sf") %>%
worldrn st_make_valid()
# define a long & slim polygon that overlaps the meridian line & set its CRS
# Centered in lon 133
<- 180 - 133
offset
# build a polygon
<- st_polygon(x = list(rbind(
polygon c(-0.0001 - offset, 90),
c(0 - offset, 90),
c(0 - offset, -90),
c(-0.0001 - offset, -90),
c(-0.0001 - offset, 90)))) %>%
st_sfc() %>%
st_set_crs(4326)
# set the polygons
<- worldrn %>%
world2 st_difference(polygon) %>%
st_transform(crs = target_crs)
Set the values for hydro waste to the new target crs.
<- df %>%
coords rename(lat=lat_wwtp,lon=lon_wwtp) %>%
::st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
sf::st_transform(crs = target_crs) sf
Set the colors.
library(RColorBrewer)
<- RColorBrewer::brewer.pal(12,"Set3")
my_palette
<- c("1"="#8DD3C7",
my_values "2"="#FFFFB3",
"3"="#BEBADA",
"4"="#FB8072",
"5"="#80B1D3",
"6"="#FDB462",
"7"="#B3DE69",
"8"="#FCCDE5",
"9"="#D9D9D9",
"10"="#BC80BD",
"11"="#CCEBC5",
"12"="#FFED6F")
<-c("Europe", "United States",
my_labels"Brazil", "Mexico",
"China", "Canada",
"Australia", "South Africa",
"India", "New Zealand",
"Peru", "Remaining Countries")
Make the mollweide, more info on how to set the projections here: https://epsg.io/54009
ggplot() +
geom_sf(data = world3, aes(group = admin),
fill = "#f5f5f5") +
geom_sf(data = coords,
mapping = aes(color=factor(source)),
key_glyph = draw_key_rect,
size=0.1) +
scale_color_manual(labels=my_labels,values=my_values)+
labs(title="Wastewater Plants",
subtitle="Concentrated point sources of residual contaminant loads into surface waters",
caption="DataSource: #TidyTuesday 2022 week38 Hydro Wastewater | DataViz: Federica Gazzelloni @fgazzelloni",
color="Source of\nwaterwaste")+
coord_sf()+
::theme_map() +
ggthemestheme(plot.title = element_text(size=14,face="bold"),
plot.subtitle = element_text(size=12,face="bold"),
text=element_text(family="Roboto Condensed",color="#89a5b9"),
panel.grid = element_line(color="#bfd0dd"),
plot.background = element_rect(fill="#275477",color="#275477"),
panel.background = element_rect(fill="#275477",color="#275477"),
legend.background = element_blank(),
legend.position = c(-0.05,0.05),
legend.key = element_rect(size=4))
Save it.
ggsave("w38_hydro_waterwaste.png",
dpi=320,
width = 10,
height = 5)