geofacet - siatka z województwami
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
# 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