Use Carto for metro map. master
authorFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Mon, 9 Oct 2023 13:35:35 +0000 (21:35 +0800)
committerFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Mon, 9 Oct 2023 13:35:35 +0000 (21:35 +0800)
WA_active_schools.R

index ae59595e3d2532f327215e2a91cdc24f0cfc0984..7ca4a00d904183acc7a806800a1b57f6d597e3b4 100644 (file)
@@ -78,30 +78,32 @@ sfg_metro <- st_polygon(list(rbind(c(lon.metro[1],lat.metro[1]),
                                    c(lon.metro[1],lat.metro[2]),
                                    c(lon.metro[1],lat.metro[1])
                                    )))
                                    c(lon.metro[1],lat.metro[2]),
                                    c(lon.metro[1],lat.metro[1])
                                    )))
-metroTiles <- get_tiles(st_transform(st_sfc(sfg_metro, crs = 4326), 3857), provider = "Stadia.Stamen.TonerLite", crop = TRUE, zoom = 11)
+metroTiles <- get_tiles(st_transform(st_sfc(sfg_metro, crs = 4326), 3857), provider = "CartoDB.PositronNoLabels", crop = TRUE, zoom = 11)
 # Let's look at secondary school only
 # 95th percentile of school size
 secon95th <- quantile(shape.metro.df[,"totalsecon">0]$totalsecon,probs = .95)
 ggplot() +
 # Let's look at secondary school only
 # 95th percentile of school size
 secon95th <- quantile(shape.metro.df[,"totalsecon">0]$totalsecon,probs = .95)
 ggplot() +
-  geom_spatraster_rgb(data = metroTiles) +
-  geom_sf(data = filter(shape.metro.df, totalsecon > 0),
-             aes(color = totalsecon,
-                 size = totalsecon),
-             ) +
-  geom_sf_label(data = filter(shape.metro.df, totalsecon > secon95th), # name top 5% schools
-             aes(x = longitude, 
-                 y = latitude,
-                 label = schoolname),
-            size = 2) +
-  scale_color_viridis(option="viridis",
-                      name = "Number\nof pupils") +
-  guides(size = 'none') + # Do not show legend for size, as color is the main key
-  theme(legend.position = "right",
-        axis.text = element_blank(),
-        axis.ticks = element_blank()) +
-  labs(title = "Western Australian secondary schools",
-       subtitle = "Perth metro area",
-       caption = "Map tiles by Stamen Design, under CC BY 3.0.\nMapdata by OpenStreetMap, under ODbL.
-       School data © Government of WA 2022.\n Dep. of Education & Training.",
+    geom_spatraster_rgb(data = metroTiles) +
+    geom_sf(data = filter(shape.metro.df, totalsecon > 0),
+            aes(color = totalsecon,
+                size = totalsecon)
+            ) +
+    geom_sf_text(data = filter(shape.metro.df, totalsecon > secon95th), # name top 5% schools
+                 aes(x = longitude,
+                     y = latitude,
+                     label = schoolname),
+                 size = 2) +
+    scale_color_viridis(option="cividis",
+                        name = "Number\nof pupils") +
+    guides(size = 'none') + # Do not show legend for size, as color is the main key
+    theme_minimal() +
+    theme(legend.position = "right",
+          panel.grid.major = element_line(colour = "white"),
+          axis.ticks = element_blank()) +
+    labs(title = "Western Australian secondary schools",
+         subtitle = "Perth metro area",
+         caption = "Map tiles © CARTO. Mapdata by OpenStreetMap, under ODbL.\nSchool data © Government of WA, Dep. of Education & Training.",
        x="",
        y="")
        x="",
        y="")
+
+ggsave("WA_schools.png", units = "cm", width = 15, height = 15, dpi = 300, bg = "white", scale = 1.5)