-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gantt_charts_for_Wellcome.R
23 lines (19 loc) · 1.13 KB
/
Gantt_charts_for_Wellcome.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(ggplot2)
library("ggpubr")
df <- read.csv("C:/Users/Elena/OneDrive - University College London/Desktop/Surprise study/Surprise_pilots_dates_and_platforms.csv")
df$duration <- as.numeric(df$duration)
df$start_dates <- as.Date(df$start_dates)
# Calculate end dates
df$end_dates <- df$start_dates + df$duration
# Define colors for each platform
platform_colors <- c("Prolific " = "darkblue", "Testable Minds " = "#529EFF", "Amazon MTurk " = "darkorange" )
# Create Gantt chart with colors and legend
ggplot(df, aes(x = start_dates, xend = end_dates, y = tasks, yend = tasks, color = platforms)) +
geom_segment(size = 10) +
geom_text(aes(x = start_dates + duration/2, y = tasks, label = paste("n=", participants)),
position = position_nudge(y = 0),
size = 3.2, color = "white") +
scale_color_manual(values = platform_colors) + # Assign colors based on platforms
labs(title = "Surprise Task Recruitment, Total n = 533", x = "Timeline", y = "Tasks", color = "Platforms") +
theme_minimal() + # You can choose different themes as per your preference
guides(color = guide_legend(title = "Platforms")) # Legend title