## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse=TRUE,
  comment = "#>",
  cache = FALSE,
  fig.width = 7,
  fig.height = 5,
  eval = nzchar(Sys.getenv("COMPILE_VIG"))
)

## -----------------------------------------------------------------------------
library(cansim)

names(list_cansim_cubes())

## -----------------------------------------------------------------------------
library(dplyr, warn.conflicts = FALSE)

list_cansim_cubes() %>% 
  filter(grepl("Labour force characteristics",cubeTitleEn), 
         grepl("economic region",cubeTitleEn)) %>% 
  select(cansim_table_number,cubeTitleEn)

## -----------------------------------------------------------------------------
library(tidyr)

selected_table <- "14-10-0293"

data <-get_cansim(selected_table) %>% 
  filter(grepl("Mainland|Vancouver Island|Okanagan", GEO),
         Date>=as.Date("2015-01-01"),
         `Labour force characteristics`=="Unemployment rate") %>%
  select(Date, GEO, Statistics, val_norm) %>%
  spread(key="Statistics", value=val_norm)

## ----fig.alt="Vignette example plot, unemployent rate"------------------------
library(ggplot2)
ggplot(data, aes(x=Date, group = GEO,y=Estimate)) +
  geom_ribbon(aes(ymin=Estimate - `Standard error of estimate`,
                  ymax=Estimate + `Standard error of estimate`, fill=""),
              alpha=0.8) +
  geom_line(aes(color=GEO)) +
  scale_y_continuous(labels=scales::percent) +
  scale_fill_manual(name = "", values="grey80", label="Standard error") +
  theme_bw() + 
  labs(title = "Comparison of unemployment rate by economic region",
       y = "Unemployment Rate", 
       x = "",
       color = "",
       caption=paste0("CANSIM ", selected_table))

