|
| 1 | +--- |
| 2 | +title: "NEFSC bottom trawl survey strata" |
| 3 | +format: pdf |
| 4 | +execute: |
| 5 | + warning: FALSE |
| 6 | +--- |
| 7 | + |
| 8 | +```{r} |
| 9 | +#| eval: TRUE |
| 10 | +#| echo: FALSE |
| 11 | +
|
| 12 | +knitr::opts_chunk$set(echo = FALSE, |
| 13 | + message = FALSE#, |
| 14 | + # fig.width = 12#, |
| 15 | + # out.width = "100%" |
| 16 | + ) |
| 17 | +
|
| 18 | +# load R packages |
| 19 | +library(tidyverse) |
| 20 | +library(sf) |
| 21 | +
|
| 22 | +# Load strata without printing anything to the screen |
| 23 | +strata <- st_read(dsn = here::here("data-raw/stratamap", "strata.shp")) |
| 24 | +``` |
| 25 | + |
| 26 | +```{r} |
| 27 | +plt_strata_subset <- function(data, strata) { |
| 28 | + |
| 29 | + this_data <- data |> |
| 30 | + dplyr::filter(STRATA != 0, |
| 31 | + STRATA != 99999, |
| 32 | + STRATA %in% strata) |
| 33 | + |
| 34 | + plt <- ggplot() + |
| 35 | + geom_sf(data = rnaturalearth::ne_countries(scale = 10, |
| 36 | + continent = "North America", |
| 37 | + returnclass = "sf")) + |
| 38 | + geom_sf(data = this_data, |
| 39 | + ggplot2::aes(fill = STRATA), |
| 40 | + colour = "darkgray") + # All strata |
| 41 | + ggrepel::geom_label_repel(data = this_data, |
| 42 | + aes(label = STRATA, # 4 digit strata = "STRATA", 5 digit strata = "STRATUMA" |
| 43 | + geometry = geometry), |
| 44 | + stat = "sf_coordinates", |
| 45 | + size = 2, |
| 46 | + box.padding = 0.1, |
| 47 | + label.padding = 0.1, |
| 48 | + force = 0.5, |
| 49 | + max.overlaps = 20) + # Label with offset, try adjusting max.overlaps if you want to see more labels |
| 50 | + #geom_sf_label(data = filter(strata, STR2 != 0), aes(label = STR2), size = 1) + # Label directly |
| 51 | + viridis::scale_fill_viridis() + |
| 52 | + xlab("Longitude") + ylab("Latitude") + |
| 53 | + coord_sf(xlim = c(-79,-65), ylim = c(32, 45)) # try adjusting axes to see more labels for smaller portion of footprint |
| 54 | + |
| 55 | + ggplot2::ggsave(plt, filename = here::here("data-raw/stratamap", paste0("strata_", min(strata), "_", max(strata), ".png")), |
| 56 | + width = 8, |
| 57 | + height = 12, |
| 58 | + units = "in", |
| 59 | + dpi = 300) |
| 60 | + |
| 61 | + print(plt) |
| 62 | +} |
| 63 | +``` |
| 64 | +## All strata |
| 65 | + |
| 66 | +```{r} |
| 67 | +#| out-width: 100% |
| 68 | +plt_strata_subset(data = strata, |
| 69 | + strata = 1000:9000) |
| 70 | +``` |
| 71 | + |
| 72 | +## 1000s strata |
| 73 | + |
| 74 | +```{r} |
| 75 | +#| out-width: 100% |
| 76 | +plt_strata_subset(data = strata, |
| 77 | + strata = 1000:1999) |
| 78 | +``` |
| 79 | + |
| 80 | +```{r, results = "asis"} |
| 81 | +for(i in c(1:3,6,7)) { |
| 82 | +res <- knitr::knit_child(text = knitr::knit_expand(text = "```{r} |
| 83 | + #| out-width: 100% |
| 84 | + plt_strata_subset(data = strata, |
| 85 | + strata = 1{{i}}00:1{{i}}99) |
| 86 | + ```"), |
| 87 | + quiet = TRUE) |
| 88 | +cat(paste0("### 1", i, "00s strata"), res, sep = "\n\n") |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +## 3000s strata |
| 93 | + |
| 94 | +```{r} |
| 95 | +#| out-width: 100% |
| 96 | +plt_strata_subset(data = strata, |
| 97 | + strata = 3000:3999) |
| 98 | +``` |
| 99 | + |
| 100 | +## 7000s strata |
| 101 | + |
| 102 | +```{r} |
| 103 | +#| out-width: 100% |
| 104 | +plt_strata_subset(data = strata, |
| 105 | + strata = 7000:7999) |
| 106 | +``` |
0 commit comments