mypath <- "C://Users//np83zg//OneDrive - Aalborg Universitet//Skrivebord//denmark"
setwd(mypath)
library(data.table)
mydata <- as.data.table(read.table("dat1.txt"))
mydata_2016 <- mydata[year==2016,]
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(tmap)
mun_shape <- st_read("mun_shape.shp")
## Reading layer `mun_shape' from data source `C:\Users\np83zg\OneDrive - Aalborg Universitet\Skrivebord\denmark\mun_shape.shp' using driver `ESRI Shapefile'
## Simple feature collection with 98 features and 4 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: 8.074458 ymin: 54.55906 xmax: 15.15735 ymax: 57.75238
## geographic CRS: WGS 84
mydata_2016 <- merge(mun_shape,mydata_2016,by.x="kode",by.y="workplace")
mydata_2016 <- st_transform(mydata_2016, crs="+init=epsg:3395")
## Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is
## deprecated. It might return a CRS with a non-EPSG compliant axis order.
library(cartogram)
## Warning: package 'cartogram' was built under R version 4.0.3
mun_count <- cartogram_cont(mydata_2016, "count", itermax = 5)
## Mean size error for iteration 1: 5.29623398015073
## Mean size error for iteration 2: 4.60597584810229
## Mean size error for iteration 3: 13.8951850146734
## Mean size error for iteration 4: 5.90941252307349
## Mean size error for iteration 5: 2.58394802762843
tm_shape(mun_count) + tm_polygons("count", style = "jenks", palette="BuGn") +
tm_layout(frame = FALSE, legend.position = c("right", "top"))
