Test plot variations"

knitr::opts_chunk$set(echo = FALSE, warning = TRUE, vlkr.fig.width=700)

library(ggplot2)
library(volker)

theme_set(theme_vlkr(base_size=15, base_fill = list("red")))

data <- volker::chatgpt

Categorical variables

plot_counts_one

data |> 
  plot_counts(adopter)

plot_counts_one with binary data

data |> 
  mutate(adopter = adopter == "I try new offers immediately") |> 
  plot_counts(adopter)

plot_counts_one with focus category

data |> 
  plot_counts(adopter, category="I try new offers immediately")

plot_counts_one_grouped

# Test order of items
plot_counts(data, sd_gender, adopter)

plot_counts_one_grouped with row props

# The last categories' percentage should be omitted in ordered plots
data |> 
  plot_counts(adopter, sd_gender, prop = "rows", numbers="p")

plot_counts_one_grouped with col props

# Test whether the figure is flipped
plot_counts(data, adopter, sd_gender, prop = "cols", numbers="p", ordered = -1)

plot_counts_one_grouped with reversed levels

data |> 
  mutate(adopter = factor(adopter, levels = rev(levels(adopter)))) |> 
  plot_counts(adopter, sd_gender, prop = "cols")

plot_counts_items

plot_counts(data, starts_with("cg_adoption_"), numbers = "p")

plot_counts_items_grouped

plot_counts_items_grouped(
   data, starts_with("cg_adoption_"), adopter,
   category=c("agree","strongly agree")
) 

plot_counts_items with binary data

data |> 
  mutate(across(starts_with("cg_adoption_advantage"), \(x) x > 3)) |> 
  plot_counts(starts_with("cg_adoption_advantage"))

plot_counts_one_cor

plot_counts_one_cor(data, adopter, sd_age)

plot_counts_one_cor with rows

plot_counts_one_cor(data, adopter, sd_age, prop = "rows")

plot_counts_items_cor

plot_counts_items_cor(
    data, starts_with("cg_adoption_"), sd_age,
    category=c(4,5)
) 

Metric distributions

plot_metrics_one

plot_metrics(data, sd_age)

plot_metrics_one with box

plot_metrics(data, sd_age, box=TRUE)

plot_metrics_one with ci

plot_metrics(data, sd_age, ci=TRUE)

plot_metrics_one_grouped

plot_metrics(data, sd_age, sd_gender)

plot_metrics_one_cor

plot_metrics(data, sd_age, use_work, metric=TRUE)

plot_metrics_one_cor with log

plot_metrics(data, sd_age, use_work, metric=TRUE, log=TRUE)

plot_metrics_one_cor without title

plot_metrics(data, sd_age, use_work, metric=TRUE, title = FALSE)

plot_metrics_items

plot_metrics(data, starts_with("cg_adoption_"))

plot_metrics_items_grouped

plot_metrics(data, starts_with("cg_adoption_"), sd_gender)

plot_metrics_items_cor with pearson

plot_metrics_items_cor(data, starts_with("use_"), sd_age)

plot_metrics_items_cor with spearman

plot_metrics_items_cor(data, starts_with("use_"), sd_age, method = "spearman")

plot_metrics_items_cor_items with pearson

plot_metrics_items_cor_items(data, starts_with("cg_adoption_adv"), starts_with("use_"))

plot_metrics_items_cor_items with numbers

plot_metrics_items_cor_items(
  data, starts_with("cg_adoption_adv"), 
  starts_with("use_"), 
  numbers=TRUE
)

Index: distribution by a grouping variable

data %>%
  add_index(starts_with("cg_adoption_social_")) %>%
  add_index(starts_with("cg_adoption_fearofuse_")) %>%
  add_index(starts_with("cg_adoption_advantage_")) %>%

  # Set new labels for the three index columns
  labs_apply(tribble(
    ~item_name, ~item_label,
    "idx_cg_adoption_social", "ChatGPT-Erwartung: Social",
    "idx_cg_adoption_fearofuse", "ChatGPT-Erwartung: Fear of Use",
    "idx_cg_adoption_advantage", "ChatGPT-Erwartung: Advantage"
  )) %>%

  plot_metrics_items_grouped(starts_with("idx_cg_adoption"), adopter)

Labels

Apply value labels

data %>%
  filter(sd_gender != "diverse") %>% 
  labs_apply(
    cols = sd_gender,
    values = list(
      "female" = "Weiblich",
      "male" = "Maennlich"
    )
  ) %>%
  plot_metrics(sd_age, sd_gender)


Try the volker package in your browser

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

volker documentation built on April 12, 2025, 9:16 a.m.