-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
solution by Yue for Jun Gi #337
Draft
martin-raden
wants to merge
4
commits into
main
Choose a base branch
from
yue_for_jungi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
--- | ||
title: "Yue_Z9" | ||
output: md_document | ||
date: "2024-12-04" | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
``` | ||
```{r pressure,echo=FALSE} | ||
|
||
library(ggplot2) | ||
library(tidyverse) | ||
library(readxl) | ||
|
||
#the first one | ||
#read xlsx file | ||
file<-"Volleyball Passing- USA and TU.xlsx" | ||
data <- read_excel(file,sheet = "TU sort by pass score") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
new_data <- data[2:5, 6:9] | ||
|
||
#Formation of new data | ||
colnames(new_data) <- c("Pass Score", "Attempts", "Points_Won", "Points_Lost") | ||
|
||
clean_data <- new_data %>% | ||
mutate( | ||
Pass_Score = as.factor("Pass Score"), | ||
Attempts = as.numeric(Attempts), | ||
Points_Won = as.numeric(Points_Won), | ||
Points_Lost = as.numeric(Points_Lost) | ||
) %>% | ||
pivot_longer( | ||
cols = c(Points_Won, Points_Lost), | ||
names_to = "Outcome", | ||
values_to = "Count" | ||
) %>% | ||
group_by(`Pass Score`) %>% | ||
mutate(`Pass Score` = factor(`Pass Score`, levels = c("zeros", "ones", "twos", "threes"))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can omit line 39 since factoring with predefined levels would make values that dont fit an NA.. |
||
|
||
# visualization | ||
ggplot(clean_data, aes(x = `Pass Score`, y= Count ,fill = Outcome)) + | ||
geom_bar(stat = "identity", position = "stack") + | ||
labs( | ||
title = "Stacked Bar Chart: Breakdown of Points Won and Lost by Pass Score", | ||
x = "Pass Score Categories", | ||
y = "Total Attempts" | ||
) + | ||
theme_minimal() + | ||
scale_fill_manual(values = c("Points_Won" = "skyblue", "Points_Lost" = "tomato")) | ||
|
||
#THE second | ||
#get data | ||
folder_path <- "passing stats" | ||
file_list <- list.files(path = folder_path, pattern = "\\.xlsx$", full.names = TRUE) | ||
#read every data | ||
extract_totals_data <- function(file_path) { | ||
data <- read_excel(file_path, sheet = "totals") | ||
#last 3 | ||
last_three_rows <- tail(data, 3) | ||
colnames(last_three_rows) <- as.character(last_three_rows[1, ]) | ||
#delate first row | ||
last_three_rows <- last_three_rows[-1, ] | ||
#filter | ||
filtered_data <- last_three_rows[, c("side-outs", "points", "average")] | ||
return(filtered_data) | ||
} | ||
#new data | ||
results_list <- lapply(file_list, extract_totals_data) | ||
final_results <- do.call(rbind, results_list) | ||
final_results <- final_results %>% | ||
mutate(average = round(as.numeric(average), 2)) | ||
print(final_results) | ||
|
||
final_results$points <- as.numeric(as.character(final_results$points)) | ||
final_results$average <- as.numeric(as.character(final_results$average)) | ||
|
||
#won and lost | ||
won_data <- final_results[final_results$`side-outs` == "won", ] | ||
lost_data <- final_results[final_results$`side-outs` == "lost", ] | ||
|
||
|
||
# cor | ||
won_cor <- cor(won_data$average, won_data$points, use = "complete.obs") | ||
lost_cor <- cor(lost_data$average,lost_data$points, use = "complete.obs") | ||
|
||
# plot | ||
ggplot(final_results, aes(x = average, y = points, color = `side-outs`, shape = `side-outs`)) + | ||
geom_point(size = 3) + | ||
geom_smooth(method = "lm", se = FALSE) + | ||
scale_color_manual(values = c("won" = "blue", "lost" = "red")) + | ||
scale_shape_manual(values = c("won" = 16, "lost" = 17)) + | ||
labs(title = "Correlation Between Passing Scores and Points Won/Lost", | ||
x = "Passing Score (Average)", | ||
y = "Points (Won or Lost)", | ||
color = "Side-outs", shape = "Side-outs") + | ||
annotate("text", x = 2.0, y = 180, | ||
label = paste("Won Trend (r =", round(won_cor, 2), ")", sep = ""), | ||
color = "blue", hjust = 0, vjust = 1) + | ||
annotate("text", x = 2.0, y = 170, | ||
label = paste("Lost Trend (r =", round(lost_cor, 2), ")", sep = ""), | ||
color = "red", hjust = 0, vjust = 1) + | ||
theme_minimal() + | ||
theme(legend.position = "topleft") | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ── | ||
## ✔ dplyr 1.1.4 ✔ readr 2.1.5 | ||
## ✔ forcats 1.0.0 ✔ stringr 1.5.1 | ||
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1 | ||
## ✔ purrr 1.0.2 ✔ tidyr 1.3.1 | ||
## ── 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 | ||
## New names: | ||
|
||
![](Yue_Z9_files/figure-markdown_strict/pressure-1.png) | ||
|
||
## New names: | ||
## New names: | ||
## New names: | ||
## New names: | ||
## New names: | ||
## • `` -> `...5` | ||
## • `` -> `...6` | ||
## • `` -> `...7` | ||
|
||
## # A tibble: 10 × 3 | ||
## `side-outs` points average | ||
## <chr> <chr> <dbl> | ||
## 1 won 150 2.83 | ||
## 2 lost 53 2.04 | ||
## 3 won 117 2.66 | ||
## 4 lost 30 2.14 | ||
## 5 won 140 2.69 | ||
## 6 lost 81 2.08 | ||
## 7 won 161 2.52 | ||
## 8 lost 58 2.52 | ||
## 9 won 93 2.38 | ||
## 10 lost 67 2.09 | ||
|
||
## `geom_smooth()` using formula = 'y ~ x' | ||
|
||
![](Yue_Z9_files/figure-markdown_strict/pressure-2.png) |
Binary file added
BIN
+6.98 KB
Projects/JungiHong/Yue_Z9_files/figure-markdown_strict/pressure-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.46 KB
Projects/JungiHong/Yue_Z9_files/figure-markdown_strict/pressure-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be more simple to load the meta package
library(tidyverse)
instead of individual subpackages