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

viz: dziury w cont #11

Open
bananaonthemoon opened this issue Dec 16, 2020 · 0 comments
Open

viz: dziury w cont #11

bananaonthemoon opened this issue Dec 16, 2020 · 0 comments

Comments

@bananaonthemoon
Copy link
Owner

bananaonthemoon commented Dec 16, 2020

@Nowosad kod dla kartogramów ciągłych

library(sf)
library(rmapshaper)
library(lwgeom)

library(cartogram)
library(tmap)
library(maptools)
library(dplyr)
library(sf)
library(tmaptools)

# Pobranie oraz wczytanie danych wektorowych, ustalenie układu współrzędnych
temp <- tempfile()
download.file("https://www.gis-support.pl/downloads/Powiaty.zip", temp)
unzip(temp, exdir = "dane/pobrane")
powiat = read_sf("dane/pobrane/Powiaty.shp", stringsAsFactors=FALSE) %>%
  st_transform(crs = 2180) %>% 
  select(-c(4:29))

# Uproszczenie geometrii i zapisanie pliku w formacie geopackage
powiat_simp = ms_simplify(powiat, keep_shapes = TRUE, keep = 0.2, explode = FALSE, snap = TRUE) 
powiat$geometry = powiat_simp$geometry
#write_sf(powiat, dsn = "dane/temp/powiat.gpkg")
#powiat = read_sf("dane/temp/powiat.gpkg", stringsAsFactors=FALSE) 
powiat = select(powiat, -1)

prez_p = "https://raw.github.com/bananaonthemoon/wybory/master/dane/powiaty.gpkg"
prez_pow = read_sf(prez_p, stringsAsFactors=FALSE) %>%
  st_transform(crs = 2180) %>%
  st_cast("POLYGON")

prez_pow_cont_frek = cartogram_cont(prez_pow, "t1_Frekwencja", 15, threshold = 0.1)

cont_pow_frek = tm_shape(prez_pow_cont_frek) + 
  tm_polygons(col = "#BDE5B7", lwd = 1) +
  tm_layout(frame = FALSE)

print(cont_pow_frek)
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