Skip to contents

Generate various types of Thinking Grid plots from survey data containing deliberate and automatic constraint responses.

Usage

plot_tg(
  survey_results,
  proportion_type = "overall",
  type = "depth",
  colorer = NULL,
  palette = "RdYlBu",
  zero_color = "#FFFFFF",
  gradient_scaling = "linear",
  enhanced_threshold_pct = 50,
  enhanced_expansion_factor = 1.5,
  x_label = "Directedness",
  y_label = "Stickiness",
  dc_column = "Deliberate.Constraints",
  ac_column = "Automatic.Constraints",
  condition_column = NULL,
  comparison_type = "separate",
  max_legend = NULL,
  min_legend = NULL,
  plot_title = NULL,
  legend_title = NULL,
  plot_subtitle = NULL,
  subset_condition = NULL
)

Arguments

survey_results

Data frame containing survey results with constraint response columns.

proportion_type

Type of proportion calculation: "overall" (default) for single plot showing overall response patterns, or "condition" for separate plots for different conditions (requires condition_column).

type

Type of visualization: "depth" (default) shows distance from grid center in each quadrant, "cells" shows individual cell heatmap (6x6 grid), "quadrants" shows four-quadrant summary, "horizontal" shows horizontal bands (stickiness levels), "vertical" shows vertical bands (directedness levels), "constraints" shows diagonal constraint bands.

colorer

Custom colorer function. If NULL, uses default based on other parameters. Create with create_custom_colorer().

palette

Color palette name from colorspace package (default: "RdYlBu"). Options: "RdBu", "PiYG", "BrBG", "PuOr", "RdGy".

zero_color

Color for zero values (default: "#FFFFFF").

gradient_scaling

Color gradient scaling method: "linear" (default) for standard linear color mapping, or "enhanced" for more color distinction to smaller values.

enhanced_threshold_pct

For enhanced scaling: percentage of max value used as threshold (default: 50). Values below this get enhanced distinction.

enhanced_expansion_factor

For enhanced scaling: factor controlling how much more distinction small values get (default: 1.5). Higher values mean more distinction.

x_label

X-axis label (default: "Directedness").

y_label

Y-axis label (default: "Stickiness").

dc_column

Name of deliberate constraints column (default: "Deliberate.Constraints").

ac_column

Name of automatic constraints column (default: "Automatic.Constraints").

condition_column

Column name for grouping conditions. Required when proportion_type = "condition".

comparison_type

For condition plots: "separate" (default) for side-by-side plots for 2 conditions or separate plots for 3+, or "difference" for difference plot (condition1 - condition2, requires exactly 2 conditions).

max_legend

Maximum legend value. If NULL, calculated from data.

min_legend

Minimum legend value. If NULL, calculated from data.

plot_title

Main plot title.

legend_title

Legend title. If NULL, uses "Percentage (percent)" or "Difference (percent)".

plot_subtitle

Plot subtitle. For condition plots with comparison_type = "separate", provide a vector with one subtitle per condition.

subset_condition

R expression string for subsetting data before analysis. Uses standard R syntax. All referenced columns must exist in survey_results.

Value

A list containing: plot (ggplot object or list of ggplot objects for 3+ conditions) and prop_data (calculated proportion data).

Details

The function expects constraint responses on a 1-6 scale where deliberate constraints (x-axis) range from 1 = low directedness to 6 = high directedness, and automatic constraints (y-axis) range from 1 = low stickiness to 6 = high stickiness.

For enhanced scaling, the algorithm compresses small values in the color space to give them more visual distinction. This is useful when most responses are in lower ranges.

Examples

## Create sample data for testing
set.seed(123)  ## For reproducible examples
survey_data <- data.frame(
  Deliberate.Constraints = sample(1:6, 100, replace = TRUE),
  Automatic.Constraints = sample(1:6, 100, replace = TRUE),
  treatment_group = sample(c("A", "B"), 100, replace = TRUE),
  age = sample(20:60, 100, replace = TRUE),
  experience = sample(1:5, 100, replace = TRUE)
)

## Basic overall plot
result1 <- plot_tg(survey_data)

## Cell-level heatmap with enhanced scaling for small values
result2 <- plot_tg(survey_data, 
                   type = "cells", 
                   gradient_scaling = "enhanced",
                   enhanced_threshold_pct = 30,
                   enhanced_expansion_factor = 2.0)

## Compare conditions side by side
result3 <- plot_tg(survey_data, 
                   proportion_type = "condition",
                   condition_column = "treatment_group",
                   comparison_type = "separate")

## Subset data before analysis
result4 <- plot_tg(survey_data, 
                   subset_condition = "age > 25 & experience >= 2",
                   type = "quadrants")
#> Applying subset condition: age > 25 & experience >= 2
#> Subset applied successfully. 75 rows remaining out of 100 original rows.