library(ggplot2)
library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(forcats)
data <- read_csv("attentive_cursor_simulated.csv")
## Rows: 2909 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): age_group
## dbl (3): user_id, attention, num_coords
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
ggplot(data, aes(x = age_group, fill = factor(attention))) +
  geom_bar(position = "fill") +
  scale_fill_brewer(palette = "RdYlGn", name = "Attention Level") +
  labs(
    title = "Attention Level by Age Group",
    subtitle = "Proportion of attention scores within each age group",
    x = "Age Group",
    y = "Proportion",
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold"),
    plot.subtitle = element_text(color = "gray", size = 10),
    axis.text.x = element_text(angle = 45, hjust = 1)
  )

ggplot(data, aes(x = age_group, y = num_coords, fill = age_group)) +
  geom_violin(trim = FALSE, alpha = 0.45) +
  geom_boxplot(width = 0.3, outlier.shape = NA, alpha = 1, color = "black") +
  geom_jitter(width = 0.2, alpha = 0.25, size = 0.7, color = "black") +
  stat_summary(fun = mean, geom = "point", shape = 23,
               size = 2.5, fill = "white", color = "black") +
  labs(
    title = "Cursor Activity by Age Group",
    subtitle = "Cursor coordinate distributions across age groups",
    x = "Age Group",
    y = "Number of Cursor Coordinates",
    fill = "Age Group",
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold"),
    plot.subtitle = element_text(color = "gray", size = 10),
    axis.text.x = element_text(angle = 45, size = 7),
  )