-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create plot_regions and plot_municipalities and add to readme
- Loading branch information
1 parent
82ef053
commit bc857c3
Showing
11 changed files
with
277 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#' Plot selected (or all) municipalities | ||
#' | ||
#' @description | ||
#' Plot a vector of municipalities in Denmark. Just provide the name. | ||
#' | ||
#' @param region Municipality to plot. Mutiple is supported. | ||
#' | ||
#' @export | ||
#' @importFrom ggplot2 ggplot theme_bw labs geom_sf aes guides | ||
#' | ||
#' @returns Returns a `{ggplot2}` object and prints the plot as well. | ||
#' @examples | ||
#' plot_municipalities(municipality = c("Aarhus", "Favrskov")) | ||
plot_municipalities <- function( | ||
municipality = c( | ||
"København", | ||
"Frederiksberg", | ||
"Ballerup", | ||
"Brøndby", | ||
"Dragør", | ||
"Gentofte", | ||
"Gladsaxe", | ||
"Glostrup", | ||
"Herlev", | ||
"Albertslund", | ||
"Hvidovre", | ||
"Høje-Taastrup", | ||
"Lyngby-Taarbæk", | ||
"Rødovre", | ||
"Ishøj", | ||
"Tårnby", | ||
"Vallensbæk", | ||
"Furesø", | ||
"Allerød", | ||
"Fredensborg", | ||
"Helsingør", | ||
"Hillerød", | ||
"Hørsholm", | ||
"Rudersdal", | ||
"Egedal", | ||
"Frederikssund", | ||
"Greve", | ||
"Køge", | ||
"Halsnæs", | ||
"Roskilde", | ||
"Solrød", | ||
"Gribskov", | ||
"Odsherred", | ||
"Holbæk", | ||
"Faxe", | ||
"Kalundborg", | ||
"Ringsted", | ||
"Slagelse", | ||
"Stevns", | ||
"Sorø", | ||
"Lejre", | ||
"Lolland", | ||
"Næstved", | ||
"Guldborgsund", | ||
"Vordingborg", | ||
"Bornholm", | ||
"Middelfart", | ||
"Christiansø", | ||
"Assens", | ||
"Faaborg-Midtfyn", | ||
"Kerteminde", | ||
"Nyborg", | ||
"Odense", | ||
"Svendborg", | ||
"Nordfyns", | ||
"Langeland", | ||
"Ærø", | ||
"Haderslev", | ||
"Billund", | ||
"Sønderborg", | ||
"Tønder", | ||
"Esbjerg", | ||
"Fanø", | ||
"Varde", | ||
"Vejen", | ||
"Aabenraa", | ||
"Fredericia", | ||
"Horsens", | ||
"Kolding", | ||
"Vejle", | ||
"Herning", | ||
"Holstebro", | ||
"Lemvig", | ||
"Struer", | ||
"Syddjurs", | ||
"Norddjurs", | ||
"Favrskov", | ||
"Odder", | ||
"Randers", | ||
"Silkeborg", | ||
"Samsø", | ||
"Skanderborg", | ||
"Aarhus", | ||
"Ikast-Brande", | ||
"Ringkøbing-Skjern", | ||
"Hedensted", | ||
"Morsø", | ||
"Skive", | ||
"Thisted", | ||
"Viborg", | ||
"Brønderslev", | ||
"Frederikshavn", | ||
"Vesthimmerlands", | ||
"Læsø", | ||
"Rebild", | ||
"Mariagerfjord", | ||
"Jammerbugt", | ||
"Aalborg", | ||
"Hjørring" | ||
)) { | ||
municipality <- match.arg(municipality, | ||
several.ok = TRUE | ||
) | ||
|
||
if (length(municipality) == 1) { | ||
title_text <- municipality | ||
} else if (length(municipality) > 1) { | ||
title_text <- title_collapse(municipality) | ||
} | ||
|
||
dawaR::get_map_data("kommuner") |> | ||
dplyr::filter(navn %in% municipality) |> | ||
ggplot() + | ||
geom_sf() + | ||
theme_bw() + | ||
labs(title = title_text) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Plot selected (or all) regions | ||
#' | ||
#' @description | ||
#' Plot a vector of regions in Denmark. Just provide the name. | ||
#' | ||
#' @param region Region(s) to plot | ||
#' | ||
#' @export | ||
#' @importFrom ggplot2 ggplot theme_bw labs geom_sf aes guides | ||
#' | ||
#' @returns Returns a `{ggplot2}` object and prints the plot as well. | ||
#' @examples | ||
#' plot_regions(region = c("Region Nordjylland", "Region Midtjylland")) | ||
plot_regions <- function( | ||
region = c( | ||
"Region Nordjylland", | ||
"Region Midtjylland", | ||
"Region Syddanmark", | ||
"Region Hovedstaden", | ||
"Region Sjælland" | ||
)) { | ||
region <- match.arg(region, | ||
several.ok = TRUE | ||
) | ||
|
||
if (length(region) == 1) { | ||
title_text <- region | ||
} else if (length(region) > 1) { | ||
title_text <- title_collapse(region) | ||
} | ||
|
||
dawaR::get_map_data("regioner") |> | ||
dplyr::filter(navn %in% region) |> | ||
ggplot() + | ||
geom_sf() + | ||
theme_bw() + | ||
labs(title = title_text) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
title_collapse <- function(input, comma = TRUE) { | ||
if (length(input) == 1) { | ||
return(input) | ||
} else { | ||
paste( | ||
paste(input[-length(input)], collapse = ", "), | ||
input[length(input)], | ||
sep = " & " | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters