## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 8, 
  fig.height = 4
)

## ----setup--------------------------------------------------------------------
library(ThinkingGrid)
library(gridExtra)

data_file <- system.file("extdata", "sample_data.csv", package = "ThinkingGrid")
tg_data <- read.csv(data_file)

knitr::kable(head(tg_data))

## ----basic_example1-----------------------------------------------------------
simple_depth <- plot_tg(
  tg_data,
  dc_column = "dc",
  ac_column = "ac"
)

simple_depth$plot

## ----basic_example2-----------------------------------------------------------
simple_constraints <- plot_tg(
  tg_data,
  type = "cells",
  dc_column = "dc",
  ac_column = "ac"
)

simple_constraints$plot

## ----condition_separate-------------------------------------------------------
condition_separate <- plot_tg(
  tg_data,
  type = "constraints",
  proportion_type = "condition",
  dc_column = "dc",
  ac_column = "ac",
  condition_column = "condition"
)

condition_separate$plot

## ----condition_separate2, fig.height=8, fig.width=8---------------------------
condition_separate2 <- plot_tg(
  tg_data,
  type = "vertical",
  proportion_type = "condition",
  dc_column = "dc",
  ac_column = "ac",
  condition_column = "valence"
)

condition_separate2_val0 <- condition_separate2$plot$`0`
condition_separate2_val2 <- condition_separate2$plot$`-2`

grid.arrange(condition_separate2_val0, condition_separate2_val2, ncol = 1)

## ----condition_difference, fig.height=6---------------------------------------
condition_difference <- plot_tg(
  tg_data,
  proportion_type = "condition",
  comparison_type = "difference",
  dc_column = "dc",
  ac_column = "ac",
  condition_column = "condition"
)

condition_difference$plot

## ----condition_difference2, fig.height=6--------------------------------------
condition_difference2 <- plot_tg(
  tg_data,
  proportion_type = "condition",
  comparison_type = "difference",
  dc_column = "dc",
  ac_column = "ac",
  condition_column = "condition",
  gradient_scaling = "enhanced",
  enhanced_threshold_pct = 40,
  enhanced_expansion_factor = 2,
)

condition_difference$plot

## ----create_tg_animation------------------------------------------------------
create_tg_animation(
  tg_data,
  proportion_type = "condition",
  dc_column = "dc",
  ac_column = "ac",
  condition_column = "valence",
  filename = "example_gif.gif"
)

