R/utils-tests.R

Defines functions example_data_uppercase example_data_lowercase example_plot_scale_fill example_plot_scale_colour unique_data1

# Pull unique values from gg$data[[1]]
unique_data1 <- function(p, name) {
  g <- ggplot2::ggplot_build(p)
  unique(g$data[[1]][[name]])
}

example_plot_scale_colour <- function() {
  ggplot2::ggplot(
    r2dii.plot::sda %>%
      filter(.data$emission_factor_metric == "projected")
  ) +
    ggplot2::geom_line(
      ggplot2::aes(
        x = .data$year,
        y = .data$emission_factor_value,
        colour = .data$region
      )
    )
}

example_plot_scale_fill <- function() {
  ggplot2::ggplot(
    r2dii.plot::sda %>%
      filter(.data$emission_factor_metric == "projected")
  ) +
    ggplot2::geom_bar(
      ggplot2::aes(
        x = .data$year,
        y = .data$emission_factor_value,
        fill = .data$region
      ),
      stat = "identity"
    )
}

example_data_lowercase <- function() {
  tibble::tibble(
    x = rep(1:5, 3), val = sample(1:100, 15),
    variable = rep(c("ice", "electric", "hybrid"), 5)
  )
}

example_data_uppercase <- function() {
  tibble::tibble(
    x = rep(1:5, 3), val = sample(1:100, 15),
    variable = rep(c("ICE", "Electric", "Hybrid"), 5)
  )
}
2DegreesInvesting/r2dii.colours documentation built on May 7, 2024, 4:49 p.m.