Skip to content

jmarshallnz/statsNZ

Repository files navigation

Build Status Coverage Status

statsNZ

The statsNZ package allows access to the StatisticsNZ API from within R.

This is very much a work in progress! The StatisticsNZ API is brand new and still in the testing phase.

This package will very likely change in the future!

EDIT: 21 February 2023. This no longer functions - the API has disappeared and has been replaced with something new.

See here for details: https://github.com/StatisticsNZ/open-data-api

Installation

statsNZ is not currently available from CRAN, but you can install it from github with:

# install.packages("devtools")
devtools::install_github("jmarshallnz/statsNZ")

Usage

library(statsNZ)

#' Take a look at the expected what data are available
available_stats()

#' See what groups are available for the alcohol statistics
get_groups('ALC')

#' Fetch some statistics for the Litres of Beverage consumed
alc <- get_stats("ALC", "Litres of Beverage")

#' Some of this information is yearly totals rather than quarterly, so to
#' plot we first filter some stuff out

library(dplyr)
library(ggplot2)
alc %>%
  filter(substr(SeriesReference, 1, 4) != 'ALCQ') %>%
  ggplot(aes(x=Period, y=DataValues)) +
    geom_line(aes(colour=SeriesTitle1)) +
    xlab("") +
    ylab("Litres of Beverage") + 
    theme(legend.title = element_blank())

About

R package for accessing the StatisticsNZ API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages