From de1b68b03d769813a30ce84c14defd2ee18732d7 Mon Sep 17 00:00:00 2001 From: Jon Jablonski Date: Tue, 21 Jan 2025 14:19:11 -0800 Subject: [PATCH] PR changes in episode 7 and maintainers list. --- .../07-vector-shapefile-attributes-in-r.Rmd | 33 +++++++++---------- index.md | 10 +----- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/episodes/07-vector-shapefile-attributes-in-r.Rmd b/episodes/07-vector-shapefile-attributes-in-r.Rmd index 9d9d7173..46cfaf8b 100644 --- a/episodes/07-vector-shapefile-attributes-in-r.Rmd +++ b/episodes/07-vector-shapefile-attributes-in-r.Rmd @@ -48,6 +48,7 @@ and other prerequisites you will need to work through the examples in this episode. + :::::::::::::::::::::::::::::::::::::::::::::::::: This episode continues our discussion of vector layer attributes and covers how @@ -58,7 +59,7 @@ attribute values. ## Load the Data -We will continue using the `sf`, `terra` and `ggplot2` packages in this +We will continue using the `sf`, `terra` `dplyr` and `ggplot2` packages in this episode. Make sure that you have these packages loaded. We will continue to work with the three ESRI `shapefiles` (vector layers) that we loaded in the [Open and Plot Vector Layers in R](06-vector-open-shapefile-in-r/) episode. @@ -86,7 +87,7 @@ point_HARV We can use the `ncol` function to count the number of attributes associated with a spatial object too. Note that the geometry is just another column and -counts towards the total. +counts towards the total. Let's look at the roads file: ```{r shapefile-attributes} ncol(lines_HARV) @@ -215,7 +216,7 @@ connecting line thickness to a data variable. ```{r plot-subset-shapefile-unique-colors, fig.cap="Map of the footpaths in the study area where each feature is colored differently."} ggplot() + - geom_sf(data = footpath_HARV, aes(color = factor(OBJECTID)), size = 1.5) + + geom_sf(data = footpath_HARV, aes(color = factor(OBJECTID)), linewidth = 1.5) + labs(color = 'Footpath ID') + ggtitle("NEON Harvard Forest Field Site", subtitle = "Footpaths") + coord_sf() @@ -250,7 +251,7 @@ Now let's plot that data: ```{r harv-boardwalk-map, fig.cap="Map of the boardwalks in the study area."} ggplot() + - geom_sf(data = boardwalk_HARV, size = 1.5) + + geom_sf(data = boardwalk_HARV, linewidth = 1.5) + ggtitle("NEON Harvard Forest Field Site", subtitle = "Boardwalks") + coord_sf() ``` @@ -283,7 +284,7 @@ Now we can plot the data: ```{r harv-stone-wall-map, fig.cap="Map of the stone walls in the study area where each feature is colored differently."} ggplot() + - geom_sf(data = stoneWall_HARV, aes(color = factor(OBJECTID)), size = 1.5) + + geom_sf(data = stoneWall_HARV, aes(color = factor(OBJECTID)), linewidth = 1.5) + labs(color = 'Wall ID') + ggtitle("NEON Harvard Forest Field Site", subtitle = "Stonewalls") + coord_sf() @@ -389,7 +390,7 @@ Now we can create our plot. ```{r harv-path-line-types, fig.cap="Roads and trails in the area with different line thickness for each type of paths."} ggplot() + - geom_sf(data = lines_HARV, aes(size = TYPE)) + + geom_sf(data = lines_HARV, aes(linewidth = TYPE)) + scale_size_manual(values = line_width) + ggtitle("NEON Harvard Forest Field Site", subtitle = "Roads & Trails - Line width varies") + @@ -405,21 +406,17 @@ ggplot() + We can add a legend to our plot too. When we add a legend, we use the following elements to specify labels and colors: -- `bottomright`: We specify the location of our legend by using a default - keyword. We could also use `top`, `topright`, etc. -- `levels(objectName$attributeName)`: Label the legend elements using the - categories of levels in an attribute (e.g., levels(lines\_HARV$TYPE) means - use the levels boardwalk, footpath, etc). -- `fill =`: apply unique colors to the boxes in our legend. `palette()` is the - default set of colors that R applies to all plots. Let's add a legend to our plot. We will use the `road_colors` object that we created above to color the legend. We can customize the appearance of our legend by manually setting different parameters. + + + ```{r add-legend-to-plot, fig.cap="Roads and trails in the study area using thicker lines than the previous figure."} ggplot() + - geom_sf(data = lines_HARV, aes(color = TYPE), size = 1.5) + + geom_sf(data = lines_HARV, aes(color = TYPE), linewidth = 1.5) + scale_color_manual(values = road_colors) + labs(color = 'Road Type') + ggtitle("NEON Harvard Forest Field Site", @@ -435,7 +432,7 @@ parameters. ```{r modify-legend-plot, fig.cap="Map of the paths in the study area with large-font and border around the legend."} ggplot() + - geom_sf(data = lines_HARV, aes(color = TYPE), size = 1.5) + + geom_sf(data = lines_HARV, aes(color = TYPE), linewidth = 1.5) + scale_color_manual(values = road_colors) + labs(color = 'Road Type') + theme(legend.text = element_text(size = 20), @@ -449,7 +446,7 @@ ggplot() + new_colors <- c("springgreen", "blue", "magenta", "orange") ggplot() + - geom_sf(data = lines_HARV, aes(color = TYPE), size = 1.5) + + geom_sf(data = lines_HARV, aes(color = TYPE), linewidth = 1.5) + scale_color_manual(values = new_colors) + labs(color = 'Road Type') + theme(legend.text = element_text(size = 20), @@ -516,7 +513,7 @@ line width. ```{r harv-paths-bike-horses, fig.cap="Roads and trails in the area highlighting paths where horses and bikes are allowed."} ggplot() + geom_sf(data = lines_HARV) + - geom_sf(data = lines_showHarv, aes(color = BicyclesHo), size = 2) + + geom_sf(data = lines_showHarv, aes(color = BicyclesHo), linewidth = 2) + scale_color_manual(values = "magenta") + ggtitle("NEON Harvard Forest Field Site", subtitle = "Roads Where Bikes and Horses Are Allowed") + @@ -562,7 +559,7 @@ Now we can create our plot: ```{r colored-state-boundaries, fig.cap="Map of the continental United States where the state lines are colored by region."} ggplot() + - geom_sf(data = state_boundary_US, aes(color = region), size = 1) + + geom_sf(data = state_boundary_US, aes(color = region), linewidth = 1) + scale_color_manual(values = colors) + ggtitle("Contiguous U.S. State Boundaries") + coord_sf() diff --git a/index.md b/index.md index a7a99fd4..b9a3a26a 100644 --- a/index.md +++ b/index.md @@ -1,13 +1,5 @@ --- -maintainers: -- Leah Wasser -- Jemma Stachelek -- Tyson Swetnam -- Lauren O'Brien -- Janani Selvaraj -- Lachlan Deer -- Chris Prener -- Juan Fung + site: sandpaper::sandpaper_site ---