# install.packages("sf")
library(sf)
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
tmpdir <- tempdir()
url <- paste0("http://census.cso.ie/censusasp/saps/boundaries/",
"Census2011_NUTS3_generalised20m.zip")
file <- basename(url)
download.file(url, file)
unzip(file, exdir = tmpdir)
shapeFile <- paste0(tmpdir,"\\Census2011_NUTS3_generalised20m.shp")
shp <- st_read(shapeFile, stringsAsFactors = F)
## Reading layer `Census2011_NUTS3_generalised20m' from data source `C:\Users\horgane\AppData\Local\Temp\RtmpEfwe62\Census2011_NUTS3_generalised20m.shp' using driver `ESRI Shapefile'
## Simple feature collection with 8 features and 18 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: 17491.14 ymin: 19589.93 xmax: 334558.6 ymax: 466919.3
## epsg (SRID): NA
## proj4string: +proj=tmerc +lat_0=53.5 +lon_0=-8 +k=1.000035 +x_0=200000 +y_0=250000 +datum=ire65 +units=m +no_defs
# # or get from http://census.cso.ie/censusasp/saps/boundaries/ED_SA%20Disclaimer1.htm
# shp <- st_read("shapefile.shp", stringsAsFactors = F)
shp[, 5:7]
## Simple feature collection with 8 features and 3 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: 17491.14 ymin: 19589.93 xmax: 334558.6 ymax: 466919.3
## epsg (SRID): NA
## proj4string: +proj=tmerc +lat_0=53.5 +lon_0=-8 +k=1.000035 +x_0=200000 +y_0=250000 +datum=ire65 +units=m +no_defs
## NUTS3 NUTS3NAME GEOGID geometry
## 1 IE024 South-East (IE) R6 MULTIPOLYGON (((226795.5 90...
## 2 IE025 South-West (IE) R7 MULTIPOLYGON (((18146.05 95...
## 3 IE011 Border R1 MULTIPOLYGON (((306570.4 30...
## 4 IE012 Midland R5 MULTIPOLYGON (((223420.6 29...
## 5 IE013 West R8 MULTIPOLYGON (((48596.74 26...
## 6 IE021 Dublin R2 MULTIPOLYGON (((324832.3 22...
## 7 IE022 Mid-East R3 MULTIPOLYGON (((283537.7 29...
## 8 IE023 Mid-West R4 MULTIPOLYGON (((195253.8 21...
# install.packages("tmap")
library(tmap)
t <- tm_shape(shp) + tm_fill(col="TOTAL2011")
t
## Some legend labels were too wide. These labels have been resized to 0.66, 0.60, 0.60. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger.
t <- tm_shape(shp) +
tm_fill(col="TOTAL2011", palette = viridisLite::viridis(20),
colorNA = "grey50", legend.reverse = TRUE,
title = "Population 2011")
t
## Some legend labels were too wide. These labels have been resized to 0.60, 0.60, 0.66. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger.
See https://www.rdocumentation.org/packages/classInt/versions/0.1-7/topics/classIntervals for an explanation of the discrete options available for style.
t <- tm_shape(shp) +
tm_fill(col="TOTAL2011", style="fisher", n = 3)
t
## Some legend labels were too wide. These labels have been resized to 0.66. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger.
t <- tm_shape(shp) +
tm_fill(col="TOTAL2011") +
tm_borders(col = "black", lwd = 1)
t
## Some legend labels were too wide. These labels have been resized to 0.66, 0.60, 0.60. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger.
t <- tm_shape(shp) +
tm_fill(col="TOTAL2011",
palette = viridisLite::viridis(20),
style="cont", legend.reverse = TRUE,
title = "Population 2011") +
tm_borders(col = "black") +
tm_layout(frame = FALSE, scale = 1.6)
t
# install.packages("pxR")
library(pxR)
## Loading required package: stringr
## Loading required package: reshape2
## Loading required package: RJSONIO
## Loading required package: plyr
importPX <- function(filename = "data.px"){
px <- read.px(filename)
if(!is(px, "px")) stop("Input data is not a px object.")
data <- as.data.frame(px)
string <- names(data)
remove <- c("Year", "Quarter", "Month", "value","CensusYear","HalfYear")
z <- string [! string %in% remove]
rowized <- dcast(data, formula=paste(paste(z, collapse= " + ")," ~ ... "))
return(rowized)
}
df <- importPX(paste0("https://statbank.cso.ie/px/pxeirestat/",
"Database/eirestat/Quarterly%20National%20Household",
"%20Survey%20Main%20Results/QNQ22.px"))
# # or
# df <- importPX("C:\\Users\\path\\to\\your\\file\\QNQ22.px")
df$NUTS.3.Regions <- revalue(df$NUTS.3.Regions,
c("South-East"="South-East (IE)",
"South-West"="South-West (IE)"))
# install.packages("dplyr")
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
shp <- subset(shp, select = -c(NUTS1, NUTS1NAME, NUTS2, NUTS2NAME,
NUTS3, MALE2011, FEMALE2011, TOTAL2011, PPOCC2011,
UNOCC2011, HS2011, VACANT2011, PCVAC2011, TOTAL_AREA,
LAND_AREA, CREATEDATE))
shp <- left_join(shp, df, by = c("NUTS3NAME" = "NUTS.3.Regions"))
## Warning: Column `NUTS3NAME`/`NUTS.3.Regions` joining character vector and
## factor, coercing into character vector
var <- "2017Q2" # Choose from "1997Q4" to "2017Q2"
stat <- as.character(levels(shp$Statistic)[4]) # Choose from 1 to 5
# [1] Persons aged 15 years and over in Employment (Thousand)
# [2] Unemployed Persons aged 15 years and over (Thousand)
# [3] Persons aged 15 years and over in Labour Force (Thousand)
# [4] ILO Unemployment Rate (15 - 74 years) (%)
# [5] ILO Participation Rate (15 years and over) (%)
t <- tm_shape(shp[shp$Statistic == stat, ]) +
tm_fill(col=var,
palette = viridisLite::viridis(20),
style = "cont", colorNA = "grey50",
title = "ILO Unemployment Rate (%),\n(15 - 74 years), 2017Q2",
popup.vars=c("GEOGID", var)) +
tm_borders(col = "black") +
tm_layout(frame = FALSE, scale = 1.1, legend.width = 0.7)
t
# tmap_mode("view")
# t
# tmap_mode("plot")
# t