library(readr)
motivation <- read_csv("~/Downloads/motivation.csv")
## Rows: 9 Columns: 30
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (6): Gender, Afdeling_coschap, Previous_Ed, Failed, relevance_coschap, ...
## dbl (24): User ID, Intrinsic Motivation_Med, Identified Regulation_Med, Intr...
## 
## ℹ 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.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ purrr     1.0.2
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ 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
# Load necessary libraries
library(dplyr)
library(tidyr)
library(ggplot2)
# Check the column names
names(motivation)
##  [1] "User ID"                    "Intrinsic Motivation_Med"  
##  [3] "Identified Regulation_Med"  "Introjected Regulation_Med"
##  [5] "External Regulation_Med"    "Amotivation_Med"           
##  [7] "AM_Med"                     "CM_Med"                    
##  [9] "RAM_Med"                    "Intrinsic Motivation_KNO"  
## [11] "Identified Regulation KNO"  "Introjected Regulation_KNO"
## [13] "External Regulation_KNO"    "Amotivation_KNO"           
## [15] "AM_KNO"                     "CM_KNO"                    
## [17] "RAM_KNO"                    "Level_Completed"           
## [19] "Questions_Attemped"         "Gender"                    
## [21] "Block"                      "Afdeling_coschap"          
## [23] "Previous_Ed"                "Failed"                    
## [25] "relevance_coschap"          "relevance_career"          
## [27] "Both"                       "Questionaire_only"         
## [29] "Questions_only"             "None"
# Summarize the data to count the number of 1s in each category
counts <- motivation %>%
  summarise(
    Questionnaire = sum(Questionaire_only == 1, na.rm = TRUE),
    Both = sum(Both == 1, na.rm = TRUE),
    Questions = sum(Questions_only == 1, na.rm = TRUE),
    None = sum(None == 1, na.rm = TRUE)
  )

# Convert the summary to a long format for ggplot2
counts_long <- counts %>%
  pivot_longer(cols = everything(), names_to = "Category", values_to = "Count")

# Create a custom color palette
custom_colors <- c("Questionnaire" = "#FFB6C1",   # Baby Pink
                   "Questions" = "#89CFF0",       # Baby Blue
                   "None" = "#98FB98",                 # Baby Green
                   "Both" = "#FFFFE0")                 # Light Yellow

# Create the bar graph with custom colors
ggplot(counts_long, aes(x = Category, y = Count, fill = Category)) +
  geom_bar(stat = "identity", position = position_dodge(width = 10)) +
  scale_fill_manual(values = custom_colors) +  # Apply custom colors
  labs(title = "Participant Response Distribution", x = "Category", y = "Count") +
  theme_minimal()

# Load necessary libraries
library(ggplot2)

# Create the histogram
ggplot(motivation, aes(x = Gender, fill = Gender)) +
  geom_bar() +
  labs(title = "Number of Women and Men", x = "Gender", y = "Count") +
  scale_fill_manual(values = c("vrouw" = "pink", "man" = "#89CFF0")) +  # Custom colors for genders
  theme_minimal() +
  scale_x_discrete(labels = c("vrouw" = "Female", "man" = "Male"))

library(scales)
## 
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor
ggplot(motivation, aes(x = RAM_Med, y = RAM_KNO, color = as.factor(row.names(motivation)))) +
  geom_point(size = 5) +
  scale_color_discrete() +
  labs(title = "Scatterplot of RAM Medicine vs RAM KNO",
       x = "RAM Medicine",
       y = "RAM KNO") +
  xlim(-1, 15) + 
  ylim(-1, 15) +  
  theme_minimal() +
   theme(legend.position = "none")

motivation$Group <- ifelse(motivation$Afdeling_coschap == "KNO", "KNO", "non-KNO")


ggplot(motivation, aes(x = Group)) +
  geom_bar(fill = c("yellow", "pink")) +
  labs(x = "Group", y = "Count", title = "Distribution of KNO and non-KNO") +
   theme_minimal()

motivation$Group <- ifelse(motivation$Afdeling_coschap == "KNO", "KNO", "non-KNO")

ggplot(data= motivation, aes(x = Group, fill=relevance_coschap)) +
  geom_bar(position='fill') +
  labs(x = "Group", y = "Proportion", fill= 'relevance coschap', title='Distribution of relevance by afdeling coschap') +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

install.packages("ggmosaic", repos = "https://cloud.r-project.org/")
## 
## The downloaded binary packages are in
##  /var/folders/3g/ln4t2cvs3250dv7p12p13c_c0000gn/T//RtmpwltFw6/downloaded_packages
library(ggmosaic)
library(ggplot2)

# Assuming your data frame is named motivation
motivation$Afdeling_coschap <- as.factor(motivation$Afdeling_coschap)
motivation$relevance_coschap <- as.factor(motivation$relevance_coschap)

ggplot(data = motivation) +
  geom_mosaic(aes(x = product(Afdeling_coschap), fill = relevance_coschap), na.rm = TRUE) +
  labs(x = "Afdeling_coschap", fill = "Relevance_coschap") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

ggplot(data = motivation, aes(x = Afdeling_coschap, fill = relevance_coschap)) +
  geom_bar(position = "fill") +
  labs(y = "Proportion", x = "Afdeling_coschap", fill = "Relevance_coschap") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

ggplot(data = motivation, aes(x = Afdeling_coschap, fill = relevance_coschap)) +
  geom_bar() +
  labs(y = "Count", x = "Afdeling_coschap", fill = "Relevance_coschap") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

library(ggplot2)

# Exclude rows with NA values in Afdeling_coschap or relevance_coschap
motivation_clean <- na.omit(motivation[, c("Afdeling_coschap", "relevance_coschap")])

# Create the plot
ggplot(data = motivation_clean, aes(x = Afdeling_coschap, fill = relevance_coschap)) +
  geom_bar(position = "fill") +
  labs(y = "Proportion", x = "Afdeling_coschap", fill = "Relevance_coschap", title='Distribution of relevance by afdeling coschap') +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

ggplot(data = motivation, aes(x = relevance_coschap, y = RAM_KNO)) +
  geom_boxplot() +
  labs(
    title = "Effect of Relevance Coschap on Motivation to Study KNO",
    x = "Relevance Coschap",
    y = "Motivation to Study KNO (RAM)"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

ggplot(data = motivation, aes(x = relevance_coschap, y = RAM_KNO)) +
  geom_violin() +
  labs(
    title = "Effect of Relevance Coschap on Motivation to Study KNO",
    x = "Relevance Coschap",
    y = "Motivation to Study KNO (RAM)"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

ggplot(data = motivation, aes(x = relevance_coschap, y = RAM_KNO)) +
  geom_violin(trim = FALSE) +  # Violin plot without trimming the tails
  geom_boxplot(width = 0.1, fill = "white") +  # Box plot inside the violin plot
  labs(
    title = "Effect of Relevance Coschap on Motivation to Study KNO",
    x = "Relevance Coschap",
    y = "Motivation to Study KNO (RAM)"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

library(ggplot2)
motivation$relevance_coschap <- as.factor(motivation$relevance_coschap)
# Box plot for AM_KNO
p1 <- ggplot(data = motivation, aes(x = relevance_coschap, y = AM_KNO)) +
  geom_boxplot() +
  labs(
    title = "Effect of Relevance Coschap on AM_KNO",
    x = "Relevance Coschap",
    y = "Autonomous Motivation for KNO"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
   ylim(0,7)

# Box plot for CM_KNO
p2 <- ggplot(data = motivation, aes(x = relevance_coschap, y = CM_KNO)) +
  geom_boxplot() +
  labs(
    title = "Effect of Relevance Coschap on CM_KNO",
    x = "Relevance Coschap",
    y = "Controlled Motivation for KNO"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ylim(0,7)

# Display plots side by side
install.packages("gridExtra", repos = "https://cloud.r-project.org/")
## 
## The downloaded binary packages are in
##  /var/folders/3g/ln4t2cvs3250dv7p12p13c_c0000gn/T//RtmpwltFw6/downloaded_packages
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
grid.arrange(p1, p2, ncol = 2)

library(ggplot2)
motivation$relevance_career <- as.factor(motivation$relevance_career)
# Box plot for AM_KNO
p1 <- ggplot(data = motivation, aes(x = relevance_career, y = AM_KNO)) +
  geom_boxplot() +
  labs(
    title = "Effect of Relevance Career on AM_KNO",
    x = "Relevance Career",
    y = "Autonomous Motivation for KNO"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
   ylim(0,7)

# Box plot for CM_KNO
p2 <- ggplot(data = motivation, aes(x = relevance_career, y = CM_KNO)) +
  geom_boxplot() +
  labs(
    title = "Effect of Relevance Career on CM_KNO",
    x = "Relevance Career",
    y = "Controlled Motivation for KNO"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ylim(0,7)

# Display plots side by side
library(gridExtra)
grid.arrange(p1, p2, ncol = 2)

install.packages("ggbeeswarm", repos = "https://cloud.r-project.org/")
## 
## The downloaded binary packages are in
##  /var/folders/3g/ln4t2cvs3250dv7p12p13c_c0000gn/T//RtmpwltFw6/downloaded_packages
library(ggbeeswarm)

# Bee swarm plot for AM_KNO
p1 <- ggplot(data = motivation, aes(x = relevance_career, y = AM_KNO)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Career on AM_KNO",
    x = "Relevance Career",
    y = "Autonomous Motivation for KNO"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ylim(0, 7)

# Bee swarm plot for CM_KNO
p2 <- ggplot(data = motivation, aes(x = relevance_career, y = CM_KNO)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Career on CM_KNO",
    x = "Relevance Career",
    y = "Controlled Motivation for KNO"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ylim(0, 7)

# Display plots side by side
library(gridExtra)
grid.arrange(p1, p2, ncol = 2)

library(ggbeeswarm)
motivation$relevance_coschap <- as.factor(motivation$relevance_coschap)
library(ggplot2)

# Bee swarm plot for AM_KNO
p1 <- ggplot(data = motivation, aes(x = relevance_coschap, y = AM_KNO)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Coschap on AM_KNO",
    x = "Relevance Coschap",
    y = "Autonomous Motivation for KNO"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ylim(0, 7)

# Bee swarm plot for CM_KNO
p2 <- ggplot(data = motivation, aes(x = relevance_coschap, y = CM_KNO)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Coschap on CM_KNO",
    x = "Relevance Coschap",
    y = "Controlled Motivation for KNO"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ylim(0, 7)

# Display plots side by side
library(gridExtra)
grid.arrange(p1, p2, ncol = 2)

library(ggbeeswarm)
library(ggplot2)
library(gridExtra)

motivation$RowID <- as.factor(seq_len(nrow(motivation)))
motivation$relevance_coschap <- as.factor(motivation$relevance_coschap)
motivation$relevance_career <- as.factor(motivation$relevance_career)

# Bee swarm plot for AM_KNO with relevance_coschap
p1 <- ggplot(data = motivation, aes(x = relevance_coschap, y = AM_KNO, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Coschap on AM_KNO",
    x = "Relevance Coschap",
    y = "Autonomous Motivation for KNO",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ylim(0, 7)

# Bee swarm plot for CM_KNO with relevance_coschap
p2 <- ggplot(data = motivation, aes(x = relevance_coschap, y = CM_KNO, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Coschap on CM_KNO",
    x = "Relevance Coschap",
    y = "Controlled Motivation for KNO",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ylim(0, 7)

# Display plots side by side
grid.arrange(p1, p2, ncol = 2)

# Bee swarm plot for AM_KNO with relevance_career
p3 <- ggplot(data = motivation, aes(x = relevance_career, y = AM_KNO, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Career on AM_KNO",
    x = "Relevance Career",
    y = "Autonomous Motivation for KNO",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ylim(0, 7)

# Bee swarm plot for CM_KNO with relevance_career
p4 <- ggplot(data = motivation, aes(x = relevance_career, y = CM_KNO, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Career on CM_KNO",
    x = "Relevance Career",
    y = "Controlled Motivation for KNO",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  ylim(0, 7)

# Display plots side by side
grid.arrange(p3, p4, ncol = 2)

library(ggbeeswarm)
library(ggplot2)
library(gridExtra)

motivation$RowID <- as.factor(seq_len(nrow(motivation)))
motivation$relevance_coschap <- as.factor(motivation$relevance_coschap)
motivation$relevance_career <- as.factor(motivation$relevance_career)

# Bee swarm plot for AM_KNO with relevance_coschap
p1 <- ggplot(data = motivation, aes(x = relevance_coschap, y = Questions_Attemped, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Coschap App Engagement",
    x = "Relevance Coschap",
    y = "Questions Attempted",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Bee swarm plot for CM_KNO with relevance_coschap
p2 <- ggplot(data = motivation, aes(x = relevance_coschap, y = Level_Completed, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Coschap on App Engagement",
    x = "Relevance Coschap",
    y = "Levels Completed",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Display plots side by side
grid.arrange(p1, p2, ncol = 2)

# Bee swarm plot for AM_KNO with relevance_career
p3 <- ggplot(data = motivation, aes(x = relevance_career, y = Questions_Attemped, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Career on App Engagement",
    x = "Relevance Career",
    y = "Questions Attempted",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Bee swarm plot for CM_KNO with relevance_career
p4 <- ggplot(data = motivation, aes(x = relevance_career, y = Level_Completed, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of Relevance Career on App Engagement",
    x = "Relevance Career",
    y = "Levels Completed",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Display plots side by side
grid.arrange(p3, p4, ncol = 2)

# Replace 'YourUsername' with your actual username
setwd("~/Desktop/bachelor project")
# Verify the working directory
getwd()
## [1] "/Users/annathemistokleous/Desktop/bachelor project"