]> git.vanrenterghem.biz Git - R/project-wa-schools.git/commitdiff
Consider metro high schools only; label biggest.
authorFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Thu, 12 Oct 2017 12:57:48 +0000 (20:57 +0800)
committerFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Thu, 12 Oct 2017 12:57:48 +0000 (20:57 +0800)
WA_active_schools.R

index da884f9dc47354bbf0a9a65ba4c43098beb7d211..5076c609984c47b5368ac5202044185187e040e8 100644 (file)
@@ -14,6 +14,7 @@ shape.df <- st_read(dsn = "data/", layer = "CurrentActiveSchoolsSemester12017_Pu
 shape.df$latitude <- as.numeric(shape.df$latitude)
 shape.df$longitude <- as.numeric(shape.df$longitude)
 shape.df$totalschoo <- as.numeric(shape.df$totalschoo)
 shape.df$latitude <- as.numeric(shape.df$latitude)
 shape.df$longitude <- as.numeric(shape.df$longitude)
 shape.df$totalschoo <- as.numeric(shape.df$totalschoo)
+shape.df$totalsecon <- as.numeric(shape.df$totalsecon)
 
 # filter out remote islands
 shape.df <- filter(shape.df,longitude > 100)
 
 # filter out remote islands
 shape.df <- filter(shape.df,longitude > 100)
@@ -64,19 +65,29 @@ shape.metro.df <- filter(shape.df, abs(latitude) <= max(abs(lat.metro)),
                          abs(longitude) <= max(abs(lon.metro)),
                          abs(longitude) >= min(abs(lon.metro)))
 mapLatLon.metro <- openproj(map.metro)
                          abs(longitude) <= max(abs(lon.metro)),
                          abs(longitude) >= min(abs(lon.metro)))
 mapLatLon.metro <- openproj(map.metro)
+# Let's look at secondary school only
+# 95th percentile of school size
+secon95th <- quantile(shape.metro.df[,"totalsecon">0]$totalsecon,probs = .95)
 autoplot(mapLatLon.metro) +
 autoplot(mapLatLon.metro) +
-  geom_point(data = shape.metro.df, # geom_sf is not yet in ggplot2 on CRAN, so sticking to this for now
+  geom_point(data = filter(shape.metro.df, totalsecon > 0), # geom_sf is not yet in ggplot2 on CRAN, so sticking to this for now
              aes(x = longitude, 
                  y = latitude,
              aes(x = longitude, 
                  y = latitude,
-                 color = totalschoo),
-             show.legend = TRUE) +
+                 color = totalsecon,
+                 size = totalsecon)
+             ) +
+  geom_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="viridis",
                       name = "Number\nof pupils") +
   scale_color_viridis(option="viridis",
                       name = "Number\nof pupils") +
+  guides(size = FALSE) + # Do not show legend for size, as color is the main key
   theme(legend.position = "right",
         axis.text = element_blank(),
         axis.ticks = element_blank()) +
   theme(legend.position = "right",
         axis.text = element_blank(),
         axis.ticks = element_blank()) +
-  labs(title = "Western Australian schools",
-       subtitle = "Perth metro area only",
+  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 2017.\n Dep. of Education & Training.",
        x="",
        caption = "Map tiles by Stamen Design, under CC BY 3.0.\nMapdata by OpenStreetMap, under ODbL.
        School data © Government of WA 2017.\n Dep. of Education & Training.",
        x="",