csodata quick start guide

2022-06-10

Introduction

This guide provides a basic overview of the use of the csodata package for new users. Install (if necessary) and load the package:

# # Install or update the package:
# install.packages("csodata")

library(csodata)

Table of Contents

A list of all the table available on the cso StatBank can be downloaded with cso_get_toc. You can search throught the title field using cso_search_toc. (A “Loaded cached toc” or “Loaded cached data” message indicates that the data was retrieved from the cache, instead of being downloaded again.)

toc <- cso_get_toc()
head(toc)
#>          LastModified
#> 1 2022-06-10 00:20:00
#> 2 2022-06-10 00:20:00
#> 3 2022-06-10 00:20:00
#> 4 2022-06-10 00:20:00
#> 5 2022-06-10 00:20:00
#> 6 2022-06-10 00:20:00
#>                                                                               title
#> 1 Population Aged 15 Years  and Over at Work Whose Full - Time Education has Ceased
#> 2  Non-Family Private Households by All Male, All Female or Mixed Gender Households
#> 3          Population Aged 15 Years and Over Whose Full - Time Education has Ceased
#> 4  Non-Family Private Households by All Male, All Female or Mixed Gender Households
#> 5  Non-Family Private Households by All Male, All Female or Mixed Gender Households
#> 6          Population Aged 15 Years and Over Whose Full - Time Education has Ceased
#>      id
#> 1 CD914
#> 2 CD590
#> 3 CD915
#> 4 CD591
#> 5 CD592
#> 6 CD916

Downloading Data

To download a dataset, use cso_get_data.

tbl1 <- cso_get_data("PEA19")

Metadata can be also downloaded or displayed to console:

meta1 <- cso_get_meta("CDP06")
cso_disp_meta("CDP06")
#> Loaded cached data
#> *** METADATA ***
#> CSO Table = Annual Estimated Net Migration 1951 to 2011 per 1,000 of Average Population
#> Units = Number
#> Copyright = Central Statistics Office, Ireland
#> Time interval in data = Intercensal Period
#> Are these statistics experimental? -FALSE
#> Date last modified = 2020-10-30T11:00:00Z
#> Variables:
#> [1] "Intercensal Period" "Province or County" "Year"
#> 
#> Statistics:
#> [1] "Annual Estimated Net Migration 1951 to 2011 per 1,000 of Average Population"

Geographic Data

Geographic vector data in ESRI shapefile format can be downloaded for use in mapping. This uses a more recent map, including the 2016 revisions to the NUTS regions. Older 2011 data, which includes demographic information is also available.

shp <- cso_get_geo("NUTS2")
#> Reading layer `c2f2dbb3-289e-45cc-ae79-791cbc9339632020330-1-1uh3380.g89t' from data source `C:\Users\crowleyco\AppData\Local\Temp\RtmpMfD0OW\c2f2dbb3-289e-45cc-ae79-791cbc9339632020330-1-1uh3380.g89t.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 3 features and 8 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -10.66284 ymin: 51.41991 xmax: -5.996278 ymax: 55.44658
#> Geodetic CRS:  WGS 84

This data can be plotted using the tmap package. Here we plot the Size of each region, which is included as the "Shape__Are" column in the map data.

# install.packages("tmap")
library(tmap)
#> Warning: package 'tmap' was built under R version 4.0.5
t <- tm_shape(shp) +
        tm_fill(col="Shape__Are", 
                    palette = viridisLite::viridis(20),
                    style="cont", legend.reverse = TRUE,
                    title = "Area in Sq Meters") +
       tm_borders(col = "black") +
       tm_layout(frame = FALSE, scale = 1.3)
t

The data which has been cached locally can be manually cleared once we are done with it.

cso_clear_cache()