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

## ----setup--------------------------------------------------------------------
library(ThinkingGrid)
library(lme4)
library(sjPlot)
library(png)
library(grid)

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

knitr::kable(head(tg_data))

## ----add_depths---------------------------------------------------------------
tg_data <- add_depths(
  tg_data,
  dc = "dc",
  ac = "ac"
)

knitr::kable(head(tg_data))

## ----models_and_plots---------------------------------------------------------
free_model <- lmer(free ~ valence + (1|id), data = tg_data)
sticky_model <- lmer(sticky ~ valence + (1|id), data = tg_data)
directed_model <- lmer(directed ~ valence + (1|id), data = tg_data)
salience_model <- lmer(hybrid ~ valence + (1|id), data = tg_data)

free_plot <- plot_model(free_model, type = "pred")
sticky_plot <- plot_model(sticky_model, type = "pred")
directed_plot <- plot_model(directed_model, type = "pred")
salience_plot <- plot_model(salience_model, type = "pred")

## ----thinkgrid_quadrant_plot1-------------------------------------------------
combined_plot1 <- thinkgrid_quadrant_plot(
  p_sticky = sticky_plot,
  p_salience = salience_plot,
  p_free = free_plot,
  p_directed = directed_plot
)

combined_plot1

## ----thinkgrid_quadrant_plot2-------------------------------------------------
image_file <- system.file("extdata", "rabbiduck.png", package = "ThinkingGrid")
image <- readPNG(image_file)
image <- rasterGrob(image)

combined_plot2 <- thinkgrid_quadrant_plot(
  p_sticky = image,
  p_salience = salience_plot,
  p_free = image,
  p_directed = directed_plot
)

combined_plot2

## ----inner_theme--------------------------------------------------------------
default_inner_theme

## ----thinkgrid_plot_with_theme------------------------------------------------
library(ggplot2)

thinkgrid_quadrant_plot(
  p_sticky = image,
  p_salience = salience_plot,
  p_free = image,
  p_directed = directed_plot,
  inner_theme = ggplot2::theme_dark()
)



## ----eval = FALSE-------------------------------------------------------------
# ggplot2::ggsave("properly_rendered.jpg", combined_plot2, width = 10, height = 10, dpi = 300)

