load packages

library(tidyverse)
library(here)
library(janitor)
library(papaja)

read bin screened data

plot_data <- read_csv(here("data", "combined", "5_zdiff_binscreened.csv"))

glimpse(plot_data)
## Rows: 18,576
## Columns: 7
## $ pp_no     <chr> "pp401", "pp401", "pp401", "pp401", "pp401", "pp401", …
## $ condition <chr> "dyn", "dyn", "dyn", "dyn", "dyn", "dyn", "dyn", "dyn"…
## $ emotion   <dbl> 626, 626, 626, 626, 626, 626, 626, 626, 626, 626, 626,…
## $ trial     <chr> "trial1", "trial1", "trial1", "trial1", "trial1", "tri…
## $ muscle    <chr> "brow", "brow", "brow", "brow", "brow", "brow", "cheek…
## $ bin       <chr> "diff_bin1", "diff_bin2", "diff_bin3", "diff_bin4", "d…
## $ Zdiff     <dbl> 0.149188943, 0.159161634, -0.245679429, -0.559687470, …

Fix bin values

drop diff bit from values in bin column, keep the last 4 char from diff_bin1

plot_data$bin <- str_sub(plot_data$bin, -4) 

recode emotion conditions

adult Dynamic 626 = happy 727 = angry 828 = fear 929 = sad

plot_data <- plot_data %>%
  mutate(emotion = recode(emotion, "626" = "happy",
                         "727" = "angry",
                          "828" = "fear",
                       "929" = "sad", .default = "NA"))

fix data type

plot_data$emotion <- as.factor(plot_data$emotion)

plot_data$trial <- as.factor(plot_data$trial)

plot_data$bin <- as.factor(plot_data$bin)

plot_data$muscle <- as.factor(plot_data$muscle)

glimpse(plot_data)
## Rows: 18,576
## Columns: 7
## $ pp_no     <chr> "pp401", "pp401", "pp401", "pp401", "pp401", "pp401", …
## $ condition <chr> "dyn", "dyn", "dyn", "dyn", "dyn", "dyn", "dyn", "dyn"…
## $ emotion   <fct> happy, happy, happy, happy, happy, happy, happy, happy…
## $ trial     <fct> trial1, trial1, trial1, trial1, trial1, trial1, trial1…
## $ muscle    <fct> brow, brow, brow, brow, brow, brow, cheek, cheek, chee…
## $ bin       <fct> bin1, bin2, bin3, bin4, bin5, bin6, bin1, bin2, bin3, …
## $ Zdiff     <dbl> 0.149188943, 0.159161634, -0.245679429, -0.559687470, …
levels(plot_data$bin)
## [1] "bin1" "bin2" "bin3" "bin4" "bin5" "bin6"

Plot BROW

plot_data %>% 
  filter(muscle == "brow") %>%
  group_by(emotion, bin) %>%
  summarise(meanZ = mean(Zdiff, na.rm = TRUE)) %>%
  ggplot(aes(x = bin, y = meanZ, group = emotion, colour = emotion)) +
  geom_point() +
 geom_line() +
  theme_minimal() + 
  labs(title = "mean difference in brow muscle activity from baseline", subtitle = "response to dynamic emotion displayed by adults")

Plot CHEEK

plot_data %>% 
  filter(muscle == "cheek") %>%
  group_by(emotion, bin) %>%
  summarise(meanZ = mean(Zdiff, na.rm = TRUE)) %>%
  ggplot(aes(x = bin, y = meanZ, group = emotion, colour = emotion)) +
  geom_point() +
 geom_line() +
  theme_minimal() +
  labs(title = "mean difference in cheek muscle activity from baseline", subtitle = "response to dynamic emotion displayed by adults")

Plot brow and cheek together

plot_data %>% 
  group_by(emotion, bin, muscle) %>%
  summarise(meanZ = mean(Zdiff, na.rm = TRUE)) %>%
  ggplot(aes(x = bin, y = meanZ, group = emotion, colour = emotion)) +
  geom_point() +
 geom_line() +
  theme_minimal() +
  facet_wrap(~ muscle) +
  labs(title = "mean difference in brow and cheek muscle activity from baseline", subtitle = "response to dynamic emotion displayed by adults")