-
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.
- Loading branch information
1 parent
a1c627e
commit dc2b8b6
Showing
3 changed files
with
117 additions
and
36 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 |
---|---|---|
@@ -1 +1,48 @@ | ||
library(tidyverse) # Her får vi %>%, ggplot2 og andre smarte funktioner. | ||
library(sf) # Skal bruges til at arbejde med "simple features" (figurer). | ||
|
||
## Gemmer URL til API-kald | ||
url <- "https://api.dataforsyningen.dk/afstemningsomraader?format=geojson" | ||
|
||
# Sætter timeout til 10 minutter, fordi afstemingsstederne kan tage lang tid om at hente | ||
options(timeout = 600) | ||
|
||
# Skaber midlertidig fil | ||
geofile <- tempfile() | ||
|
||
# Henter geojson til tempfile | ||
download.file(url, geofile) | ||
|
||
# Læser datafilen ind i R | ||
geodata_st <- st_read(geofile) | ||
afstemningssteder_geodata <- st_as_sf(geodata_st) | ||
|
||
# Simplificerer geodata | ||
afstemningssteder_geodata <- rmapshaper::ms_simplify(afstemningssteder_geodata, | ||
keep = 0.01, | ||
keep_shapes = TRUE) | ||
|
||
# Skaber danmarkskort | ||
danmarkskort <- ggplot(afstemningssteder_geodata) + | ||
geom_sf() + | ||
ggthemes::theme_map() + | ||
labs(title = "Afstemningssteder i Danmark", | ||
caption = "Kilde: DAWA/DAGI") + | ||
theme(legend.position = "none", | ||
plot.title = element_text(size = 20), | ||
plot.caption = element_text(size = 10)) | ||
|
||
# Skaber kort over steder i Aarhus | ||
aarhus_kort <- afstemningssteder_geodata %>% | ||
filter(kommunenavn == "Aarhus") %>% | ||
ggplot(aes(fill = navn)) + | ||
geom_sf() + | ||
ggthemes::theme_map() + | ||
theme(legend.position = "none") | ||
|
||
danmarkskort | ||
|
||
aarhus_kort | ||
|
||
# Sætter timout tilbage til 1 minut | ||
options(timeout = 60) |
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