inst/doc/custom-levels.R

## ----packages, message=FALSE--------------------------------------------------
if (!requireNamespace("lexopsdata", quietly = TRUE)) {
  knitr::opts_chunk$set(eval = FALSE)
} else {
  library(lexopsdata)
}
library(dplyr)
library(tidyr)
library(ggplot2)
library(forcats)
library(LexOPS)

## ----hidden-setup, include=FALSE----------------------------------------------
set.seed(1)
theme_set(theme_minimal())

## ----create-col---------------------------------------------------------------
dat <- lexops |>
  mutate(emo_cond = case_when(
    AROU.Warriner >= 6 & VAL.Warriner <= 3 ~ "arou_neg",
    AROU.Warriner <= 3 & between(VAL.Warriner, 4, 6) ~ "neutral",
    TRUE ~ "none"
  ))

## ----plot-conditions-hist, fig.width=6, fig.height=3, warning=FALSE-----------
dat |>
  select(string, AROU.Warriner, VAL.Warriner, emo_cond) |>
  pivot_longer(cols = c(AROU.Warriner, VAL.Warriner), names_to = "Variable", values_to = "Value") |>
  mutate(emo_cond = fct_infreq(as.factor(emo_cond))) |>
  ggplot(aes(Value, fill = emo_cond)) +
  geom_histogram(binwidth = 0.5) +
  facet_wrap(vars(Variable)) +
  scale_fill_manual(values = c("#999999", "#E69F00", "#56B4E9"))

## ----plot-conditions-scatter, fig.width=6, fig.height=3, warning=FALSE--------
dat |>
  mutate(emo_cond = fct_infreq(as.factor(emo_cond))) |>
  ggplot(aes(AROU.Warriner, VAL.Warriner, colour = emo_cond)) +
  geom_point() +
  scale_colour_manual(values = c("#999999", "#E69F00", "#56B4E9"))

## ----generate-----------------------------------------------------------------
stim <- dat |>
  split_by(emo_cond, "arou_neg" ~ "neutral") |>
  control_for(Length) |>
  control_for(Zipf.SUBTLEX_UK, -0.1:0.1) |>
  control_for(AoA.Kuperman, -1.5:1.5) |>
  generate(20)

## ----print, eval=FALSE--------------------------------------------------------
# print(stim)

## ----print-kable, echo=FALSE--------------------------------------------------
knitr::kable(stim)

## ----plot-design, fig.width=7, fig.height=5-----------------------------------
plot_design(stim, c("AROU.Warriner", "VAL.Warriner"))

Try the LexOPS package in your browser

Any scripts or data that you put into this service are public.

LexOPS documentation built on Dec. 1, 2026, 5:06 p.m.