data_source_caption: Add data source caption to figure

View source: R/data_source_caption.R

data_source_captionR Documentation

Add data source caption to figure

Description

Citation information is retrieved from data attributes and used to create a data source caption.

Usage

data_source_caption(
  data,
  citation = NULL,
  text = "Data source:",
  author = TRUE
)

Arguments

data

a data

citation

an alternative citation object

text

a text to precide a citation.

author

A locigal whether to include an author.

Examples


pttdatahaku::ptt_read_data("tyonv_1001", "KOKO MAA") %>%
  dplyr::filter(tiedot_code == "AVPAIKAT") %>%
  { ggplot(., aes(x = time, y = values)) +
    geom_line() +
    geom_smooth() +
    labs(x = NULL,
         y = attributes(.)$codes_names$tiedot["AVPAIKAT"]) +
     data_source_caption(.)
   }

pttdatahaku::ptt_read_data("tyonv_1001", "KOKO MAA") %>%
  dplyr::filter(tiedot_code == "AVPAIKAT") %>%
  { ggplot(., aes(x = time, y = values)) +
    geom_line() +
    geom_smooth() +
    labs(x = NULL,
         y = attributes(.)$codes_names$tiedot["AVPAIKAT"]) +
     data_source_caption(., author = FALSE, text = "Tilastolähde")
   }

data <- pttdatahaku::ptt_read_data("tyonv_1001", "KOKO MAA")

cit <- attributes(data)$citation

data %>%
  dplyr::filter(tiedot_code == "AVPAIKAT") %>%
  { ggplot(., aes(x = time, y = values)) +
    geom_line() +
    geom_smooth() +
    labs(x = NULL,
         y = attributes(.)$codes_names$tiedot["AVPAIKAT"]) +
     data_source_caption(., author = FALSE, citation = cit, text = "Tilastolähde: Tilastokeskus")
   }



pttry/ggptt documentation built on May 4, 2023, 2:48 p.m.