Skip to content

Instantly share code, notes, and snippets.

@erzk
Last active July 21, 2019 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erzk/5973fe9f33bb18db5797d63c2e952cda to your computer and use it in GitHub Desktop.
Save erzk/5973fe9f33bb18db5797d63c2e952cda to your computer and use it in GitHub Desktop.
geofacet - siatka z województwami
# geofacet - Polska
# Ludność w miastach w % ogółu ludności (dane roczne)
library(dplyr)
library(geofacet)
library(ggplot2)
library(readxl)
# dane z Banku Danych Lokalnych
# https://bdl.stat.gov.pl/BDL/dane/podgrup/tablica
df <- read_excel("LUDN_2463_XPIV_20180325210755.xlsx", sheet = "DANE")
# czyszczenie
df <- df %>%
filter(Rok != "2017") %>%
select(Nazwa, Rok, Wartosc) %>%
mutate(Rok = as.numeric(Rok),
Wartosc = as.numeric(Wartosc)) %>%
rename(Województwo = Nazwa)
# siatka
grid_pl <- data.frame(
name = c("POMORSKIE", "ZACHODNIOPOMORSKIE", "WARMIŃSKO-MAZURSKIE", "KUJAWSKO-POMORSKIE", "LUBUSKIE",
"WIELKOPOLSKIE", "PODLASKIE", "MAZOWIECKIE", "ŁÓDZKIE", "DOLNOŚLĄSKIE", "OPOLSKIE",
"ŚWIĘTOKRZYSKIE", "LUBELSKIE", "ŚLĄSKIE", "MAŁOPOLSKIE", "PODKARPACKIE"),
code = c("PM", "ZP", "WN", "KP", "LB", "WP", "PD", "MZ", "LD", "DS", "OP", "SK", "LU", "SL", "MA", "PK"),
row = c(1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5),
col = c(3, 1, 4, 3, 1, 2, 5, 4, 3, 1, 2, 4, 5, 3, 4, 5),
stringsAsFactors = FALSE
)
# wykres
ggplot(df, aes(x = Rok, y = Wartosc, colour = Województwo)) +
geom_line() + # geom_point albo geom_area tez dziala
facet_geo(~Województwo, grid = grid_pl, label = "name") +
labs(title = "Ludność w miastach w % ogółu ludności (dane roczne)",
caption = "Dane: bdl.stat.gov.pl",
x = "Rok",
y = "Ludność w miastach (%)") +
theme_bw() +
theme(legend.position = "none")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment