Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lägg till region_plot #12

Open
jenast opened this issue Jan 29, 2024 · 0 comments
Open

lägg till region_plot #12

jenast opened this issue Jan 29, 2024 · 0 comments

Comments

@jenast
Copy link
Member

jenast commented Jan 29, 2024

Nåt sånt här:

plot_region <- function(region = NULL,
cex = 2,
nudge_x_prop = -0.03,
nudge_y_prop = -0.03,
jitter = FALSE,
annotation_tile = TRUE,
annotation_type = "osm",
annotation_zoom = 1){

region <- match.arg(region, choices = c("Sør", "Øst", "Vest", "Trøndelag", "Nord-Norge"))
annotation_type <- match.arg(annotation_type, choices = c("osm", "stamenwatercolor", "cartodark", "cartolight"))

norge_subset <- switch(region,
"Sør" = "Sør",
"Øst" = "Østlandet",
"Trøndelag" = "Trøndelag",
"Vest" = "Vestlandet",
"Nord-Norge" = "Nord-Norge")

flate_subset <- switch(region,
"Sør" = "Vest-Agder og Rogaland",
"Øst" = "Vestfold og Østfold",
"Trøndelag" = "Trøndelag",
"Vest" = "Vestlandet",
"Nord-Norge" = "Nord-Norge")

norge <- bombLepiSurv::get_map()

flate <- sf::read_sf(con,
Id(schema = "transects",
table = "region")) %>%
mutate(geom = sf::st_centroid(geom))

norge_sub <- norge %>%
filter(region == norge_subset)

sub_bbox <- sf::st_bbox(norge_sub)

flate_sub <- flate %>%
filter(region_long == flate_subset)

p <- ggplot(norge_sub) +
geom_sf()

if(annotation_tile){
p <- p + ggspatial::annotation_map_tile(
type = annotation_type,
cachedir = "maps/",
zoom = annotation_zoom
)
}

if(!isFALSE(jitter)){
p <- p + geom_sf(data = flate_sub,
color = "red") +
geom_sf_label(aes(label = flate),
data = flate_sub,
position = jitter,
#nudge_x = (sub_bbox$xmax - sub_bbox$xmin) * nudge_x_prop,
#nudge_y = (sub_bbox$ymax - sub_bbox$ymin) * nudge_y_prop,
label.r = unit(0.05, "lines"),
#label.size = 0.01,
label.padding = unit(0.1, "lines"),
cex = cex)
} else {
p <- p + geom_sf(data = flate_sub,
color = "red") +
geom_sf_label(aes(label = flate),
data = flate_sub,
#position = jitter,
nudge_x = (sub_bbox$xmax - sub_bbox$xmin) * nudge_x_prop,
nudge_y = (sub_bbox$ymax - sub_bbox$ymin) * nudge_y_prop,
label.r = unit(0.05, "lines"),
#label.size = 0.01,
label.padding = unit(0.1, "lines"),
cex = cex)

}

p <- p +
xlab("lon") +
ylab("lat")

return(p)

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant