03:00
Explore and plot by vector layer attributes
Challenge 2: π 3 mins
+Challenge 2: π 3 mins
Explore the attributes associated with the point_Delft
and boundary_Delft
spatial objects.
- How many attributes does each have? @@ -398,7 +487,7 @@
- Create a new object that only contains the motorways in Delft.
- How many features does the new object have? @@ -418,15 +520,35 @@
- make the lines where bicycles are not allowed THINNER than the roads where bicycles are allowed. +
- Make the lines where bicycles are not allowed THINNER than the roads where bicycles are allowed.
- Be sure to add a title and legend to your map.
- You might consider a color palette that has all bike-friendly roads displayed in a bright color. All other lines can be black.
- Use the data located in your data folder:
nl-gemeenten.shp
.
@@ -471,12 +621,24 @@ color each point by the leisure type.
+Color each point by the leisure type.
Overlay this layer on top of the
lines_Delft
layer (the streets).Create a custom legend that applies line symbols to lines and point symbols to the points.
Extra: Modify the previous plot. Tell R to plot each point, using a different symbol of shape value.
- Import
nl-gemeenten.shp
and filter only the municipalities in South Holland.
@@ -518,13 +702,26 @@
Challenge 2: π 3 mins
β£ A) location B) leisure C) osm_id
03:00
Challenge 2: π 3 mins
Challenge 3: π 5 mins
+Challenge 3: π’ 5 mins
Challenge 3: π 5 mins
05:00
levels(factor(lines_Delft$highway))
+
+motorway_Delft <- lines_Delft %>%
+ filter(highway == "motorway")
+
+motorway_Delft %>%
+ mutate(length = st_length(.)) %>%
+ select(everything(), geometry) %>%
+ summarise(total_length = sum(length))
+
+nrow(motorway_Delft)
+
+ggplot(data = motorway_Delft) +
+ geom_sf(size = 1.5) +
+ ggtitle("Mobility network of Delft", subtitle = "Motorways") +
+ coord_sf()
Challenge 4: β° 3 mins
+Challenge 4: π 3 mins
In the previous example, we set the line widths to be 1, 0.75, 0.5, and 0.25. In our case line thicknesses are consistent with the hierarchy of the selected road types, but in some cases we might want to show a different hierarchy.
Letβs create another plot where we show the different line types with the following thicknesses:
-
@@ -437,32 +559,60 @@
Challenge 4: β° 3 mins
03:00
levels(factor(lines_Delft$highway))
+
+line_widths <- c(0.25, 0.75, 0.5, 1)
+
+ggplot(data = lines_Delft_selection) +
+ geom_sf(aes(size = highway)) +
+ scale_size_manual(values = line_widths) +
+ labs(size = "Road Size") +
+ ggtitle("Mobility network of Delft", subtitle = "Roads & Cycleways - Line width varies") +
+ coord_sf()
Challenge 5: π° 5 mins
+Challenge 5: π‘ 5 mins
Create a plot that emphasizes only roads where bicycles are allowed, as follows:
-
-
05:00
levels(factor(lines_Delft_selection$highway))
+
+lines_Delft_bicycle <- lines_Delft %>%
+ filter(highway == "cycleway")
+
+ggplot() +
+ geom_sf(data = lines_Delft) +
+ geom_sf(data = lines_Delft_bicycle, color = "magenta", size = 2) +
+ ggtitle("Mobility network of Delft", subtitle = "Roads dedicated to bikes") +
+ coord_sf()
Challenge 6: π 3 mins
+Challenge 6: π 3 mins
Create a map of the municipal boundaries in the Netherlands, as follows:
Challenge 6: π 3 mins
03:00
municipal_boundaries_NL <- st_read(here("episodes", "data", "nl-gemeenten.shp"))
+str(municipal_boundaries_NL)
+levels(factor(municipal_boundaries_NL$ligtInPr_1))
+
+ggplot(data = municipal_boundaries_NL) +
+ geom_sf(aes(color = ligtInPr_1), size = 1) +
+ ggtitle("Contiguous NL Municipal Boundaries") +
+ coord_sf()
Plot multiple shapefiles
Challenge 7: π 5 mins
+Challenge 7: π 5 mins
Create a map of leisure locations only including playground
and picnic_table
:
-
-
05:00
leisure_locations_selection <- st_read(here("episodes", "data", "delft-leisure.shp")) %>%
+ filter(leisure %in% c("playground", "picnic_table"))
+
+blue_orange <- c("cornflowerblue", "darkorange")
+
+p <- ggplot() +
+ geom_sf(data = lines_Delft_selection, aes(color = highway)) +
+ scale_color_manual(name = "Line Type", values = road_colors) +
+ ggtitle("Road network and leisure")
+
+p +
+ geom_sf(data = leisure_locations_selection, aes(fill = leisure), shape = 21) +
+ scale_fill_manual(name = "Leisure Type", values = blue_orange)
+
+p +
+ geom_sf(data = leisure_locations_selection, aes(fill = leisure, shape = leisure), size = 3) +
+ scale_fill_manual(name = "Leisure Type", values = blue_orange) +
+ scale_shape_manual(name = "Leisure Type", values = c(21, 22))
Handle spatial projections
+Handling spatial projections
Challenge 8: π 3 mins
+Challenge 8: π° 3 mins
Create a map of the South Holland, as follows:
Challenge 8: π 3 mins
03:00
boundary_ZH <- municipal_boundary_NL %>%
+ filter(ligtInPr_1 == "Zuid-Holland")
+
+ggplot() +
+ geom_sf(data = boundary_ZH, aes(color ="color"), show.legend = "line") +
+ scale_color_manual(name = "", labels = "Municipal Boundaries", values = c("color" = "gray18")) +
+ geom_sf(data = boundary_Delft, aes(shape = "shape"), color = "purple", fill = "purple") +
+ scale_shape_manual(name = "", labels = "Municipality of Delft", values = c("shape" = 19)) +
+ ggtitle("Delft location in South Holland") +
+ theme(legend.background = element_rect(color = NA)) +
+ coord_sf()
Geospatial Data Carpentry for Urbanism