Graph #1: not talked about in class

Likert scale plot:

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.2     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data <- read.csv("ChenData.csv")

ame_data <- data %>%
  select(AME1, AME2, AME3, AME4, AME5) %>%
  pivot_longer(cols = everything(),
               names_to = "Question",
               values_to = "Response")

ame_summary <- ame_data %>%
  count(Question, Response) %>%
  group_by(Question) %>%
  mutate(percent = n / sum(n))

ame_summary <- ame_summary %>%
  mutate(direction = case_when(
    Response %in% c(1, 2) ~ -1,
    TRUE ~ 1
  ),
  plot_value = percent * direction)
library(scales)
## 
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor
library(dplyr)
library(ggplot2)

# 1. Clean + prepare data with proper AMES labels
ame_summary_clean <- ame_summary %>%
  filter(!is.na(Response), !is.na(plot_value)) %>%
  mutate(
    # Convert Response to an ordered factor based on the paper's 6-point scale 
    Response = factor(Response, 
                      levels = 1:6, 
                      labels = c("Not at all",
        "A little",
        "Somewhat",
        "Moderately so",
        "Very much so",
        "Completely so"
        )),
    # Map AME codes to actual AMES factors [cite: 149]
    Question = case_match(Question,
      "AME1" ~ "Confidence: I feel I can win all competitions",
      "AME2" ~ "Concentration: Nothing distracts me",
      "AME3" ~ "Motivation: I feel excited for competition",
      "AME4" ~ "Tirelessness: I have endless energy",
      "AME5" ~ "Vigor: I feel energized in sports",
      .default = Question
    )
  ) %>%
   group_by(Question) %>%
  mutate(percent = plot_value / sum(plot_value)) %>%
 ungroup()
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `Question = case_match(...)`.
## ℹ In group 1: `Question = "AME1"`.
## Caused by warning:
## ! `case_match()` was deprecated in dplyr 1.2.0.
## ℹ Please use `recode_values()` instead.
ggplot(ame_summary_clean, aes(x = Question, y = percent, fill = Response)) +
  geom_bar(stat = "identity", width = 0.7) +
  coord_flip() +
  scale_y_continuous(labels = percent_format(), expand = expansion(mult = c(0, 0.05))) +

  scale_fill_brewer(palette = "Spectral", name = "Response Level", na.translate=FALSE) + 
  labs(
    x = NULL,
    y = "Percentage of Responses",
    title = "AME1–AME5 Response Distribution",
    subtitle = "AMES scale responses from 81 male volleyball players"
  ) +
  theme_minimal() +
  theme(
    legend.position = "right",
    panel.grid.minor = element_blank(),
    panel.grid.major.y = element_blank()
  )

ScatterPlot: talked about in class

library(tidyverse)
library(scales)
t
## function (x) 
## UseMethod("t")
## <bytecode: 0x64d11e081070>
## <environment: namespace:base>
data <- read.csv("ChenData.csv")

head(data)
##   ID Gender Age School Position JerseyNO TraingHr AME1 AME2 AME3 AME4 AME5 AME6
## 1  6      1  20      2        3       18       12    3    4    4    5    4    3
## 2  6     NA  NA     NA       NA       NA       NA   NA   NA   NA   NA   NA   NA
## 3  6     NA  NA     NA       NA       NA       NA   NA   NA   NA   NA   NA   NA
## 4  7      1  22      2        1        2       10    4    4    5    5    3    3
## 5  7     NA  NA     NA       NA       NA       NA   NA   NA   NA   NA   NA   NA
## 6  8      1  19      2        1       17       10    4    5    4    6    6    6
##   AME7 AME8 AME9 AME10 AME11 AME12 AME13 AME14 AME15 AME16 AME17 AME18 PlayTime
## 1    3    4    4     4     3     2     4     4     3     3     3     3       60
## 2   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA    NA    NA       NA
## 3   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA    NA    NA       NA
## 4    2    5    4     4     3     2     3     5     4     5     4     4       60
## 5   NA   NA   NA    NA    NA    NA    NA    NA    NA    NA    NA    NA       NA
## 6    4    6    4     5     3     3     4     5     5     5     5     5       90
##   PerfomanceS BSSSmean  AMEmean   GImean round spikeF spikeP spikeL blockF
## 1          90 2.777778 3.500000 4.785714     5      0      0      0      0
## 2          NA       NA       NA       NA    NA      0      0      0      0
## 3          NA       NA       NA       NA     4      0      0      0      0
## 4          65 2.888889 3.833333 4.285714     2      4      1      0      2
## 5          NA       NA       NA       NA     4     13      4      3      3
## 6          80 2.444444 4.722222 4.500000     5     13      8      2     12
##   blockP blockL serveF serveP serveL receiveF receiveP receiveL defenseF
## 1      0      0      0      0      0       43       19        2       24
## 2      0      0      0      0      0       29       19        0       27
## 3      0      0      0      0      0       37       10        0       13
## 4      0      0      4      0      0        0        0        0        1
## 5      1      4     15      0      3        0        0        0        8
## 6      0      5     14      0      3        1        1        0        8
##   defenseP defenseL liftingF liftingP liftingL point figure topScorers
## 1        7        5        5        2        0     0     11          0
## 2       11        5        7        0        0     0     NA          0
## 3        6        3        5        2        1     0     NA          0
## 4        1        0        0        0        0     1     13          1
## 5        4        3        1        1        0     5     NA          5
## 6        4        3        1        0        0     8     13          8
##   topSpikers topServers topDiggers topRecevers topBlockers topSetters
## 1         NA          0        1.4   0.3953488        0.00       0.40
## 2         NA          0         NA   0.6551724        0.00       0.00
## 3         NA          0        1.5   0.2702703        0.00       0.50
## 4  0.2500000          0        0.5          NA        0.00       0.00
## 5  0.3076923          0        1.0          NA        0.25       0.25
## 6  0.6153846          0        0.8   1.0000000        0.00       0.00
##   concentration tireless motivation confidence vigor calm AMES
## 1            11        8          7         12    11    6   55
## 2            NA       NA         NA         NA    NA   NA   NA
## 3            NA       NA         NA         NA    NA   NA   NA
## 4            10        7         10         12    13    8   60
## 5            NA       NA         NA         NA    NA   NA   NA
## 6            17       10         11         13    13   10   74
ggplot(data ,aes(x = TraingHr, y = PerfomanceS)) +
geom_point(color = "blue", alpha = 0.6) +
geom_smooth(method = "lm", color = "red") + # Adds a trend line
  labs(title = "Training Hours vs. Performance Score",
       x = "Weekly Training Hours", y = "Performance Score")
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 188 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 188 rows containing missing values or values outside the scale range
## (`geom_point()`).

# Install packages if you haven't already:
# install.packages("ggplot2")
# install.packages("dplyr")

library(ggplot2)
library(dplyr)




data <- read.csv("ChenData.csv")


clean_data <- data %>% 
  filter(!is.na(PerfomanceS) & !is.na(AMES))


perf_median <- median(clean_data$PerfomanceS)

clean_data <- clean_data %>%
  mutate(Performance_Group = ifelse(PerfomanceS >= perf_median, 
                                    "High Performer", 
                                    "Low Performer"))

ggplot(clean_data, aes(x = AMES, fill = Performance_Group)) +
  geom_density(alpha = 0.6, color = "white") +
  scale_fill_manual(values = c("High Performer" = "purple", "Low Performer" = "lightblue")) +
  theme_minimal(base_size = 12) +
  labs(
    title = "Mental Energy Distribution by Performance Level",
    subtitle = ("High vs. low performers based on a median split of performance scores"),
    x = "Athletic Mental Energy Score (AMES)",
    y = "Density",
    fill = "Category"
  ) +
  theme(
    legend.position = "right",
    plot.title = element_text(face = "bold"),
    panel.grid.minor = element_blank()
  )

#graph 4 #Raincloud plot

install.packages("ggdist")  
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
install.packages("gghalves")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
## Warning: package 'gghalves' is not available for this version of R
## 
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
library(tidyverse)
library(ggdist)

data <- read.csv("ChenData.csv")


clean_data <- data %>%
  filter(!is.na(AME1), !is.na(PerfomanceS))


median_perf <- median(clean_data$PerfomanceS)

clean_data <- clean_data %>%
  mutate(
    PerformanceGroup = ifelse(PerfomanceS >= median_perf, "High Performance", "Low Performance"),
    PerformanceGroup = factor(PerformanceGroup, levels = c("Low Performance", "High Performance"))
  )


clean_data <- clean_data %>%
  rename(Confidence = AME1)


ggplot(clean_data, aes(x = PerformanceGroup, y = Confidence, fill = PerformanceGroup)) +
  
  # Half violin (distribution)
  stat_halfeye(
    adjust = 0.5,
    width = 0.6,
    justification = -0.2,
    point_colour = NA
  ) +
  
  # Boxplot (summary)
  geom_boxplot(
    width = 0.15,
    outlier.shape = NA,
    alpha = 0.5
  ) +
  
  # Jittered points (raw data)
  geom_jitter(
    width = 0.1,
    alpha = 0.4,
    size = 1.5
  ) +
  
  scale_fill_brewer(palette = "Set2") +
  
  labs(
    title = "Confidence Levels by Performance Group",
    subtitle = "Comparison of AME Confidence between high and low performing volleyball players",
    x = "Performance Group",
    y = "Confidence (AMES Scale)"
  ) +
  
  theme_minimal() +
  theme(legend.position = "none")