library(readr)
library(tidyverse)
library(ggplot2)
# set your home directory
home_dir = "/Users/max/Documents/Dissertation/Study 1 - Nature Pain MRI/Data & Analyses/Upload/Final_Upload/Source_Data/Fig1_Panels_a_b_d_f"
#define file paths
imm_rat_path = file.path(home_dir, "immediate_ratings.csv")
signature_path = file.path(home_dir, "signatures_allreg.csv")
# load data
imm_rat = as.data.frame(read_delim(imm_rat_path, col_names = TRUE, delim = ",", show_col_types = FALSE))
signature = as.data.frame(read_delim(signature_path, col_names = TRUE, delim = ",", show_col_types = FALSE))
nrow(imm_rat)
1764/49
nrow(signature)
set.seed(213)
filter(imm_rat, rating_content == "int")%>%
ggplot(aes(x = video, y = rating_value, fill = video)) +
geom_violin(adjust = 2, linewidth = 1) +
geom_boxplot(width = 0.2, outlier.shape = NA, linewidth = 1) +
geom_jitter(width = 0.15, height = 0.05, colour = "#979797",size = 0.8) +
xlab("Environment") + ylab("Intensity rating") +
ggtitle("Intensity") +
scale_y_continuous(limits = c(0, 9), breaks=c(0, 2, 4, 6, 8)) +
stat_summary(fun=mean,shape=19,col="#CB4335", geom='point', size = 2) +
scale_x_discrete(labels=c("Nature","Urban","Indoor")) +
theme(plot.title = element_text(size=24, face = "bold", hjust = 0.5, family = "Arial"),
legend.position = "none",
strip.text = element_text(size=22),
axis.text = element_text(size=22),
axis.title = element_text(size=24)) +
scale_fill_manual(name = "Environments", values=c("#27AE60",
"#CACFD2",
"#F0F3F4"))
set.seed(1)
filter(imm_rat, rating_content == "unp")%>%
ggplot(aes(x = video, y = rating_value, fill = video)) +
geom_violin(adjust = 2, linewidth = 1) +
geom_boxplot(width = 0.2, outlier.shape = NA, linewidth = 1) +
geom_jitter(width = 0.15, height = 0.05, colour = "#979797",size = 0.8) +
xlab("Environment") + ylab("Unpleasantness rating") +
ggtitle("Unpleasantness") +
scale_y_continuous(limits = c(0, 9), breaks=c(0, 2, 4, 6, 8)) +
stat_summary(fun=mean,shape=19,col="#CB4335", geom='point', size = 2) +
scale_x_discrete(labels=c("Nature","Urban","Indoor")) +
theme(plot.title = element_text(size=24, face = "bold", hjust = 0.5, family = "Arial"),
legend.position = "none",
strip.text = element_text(size=22),
axis.text = element_text(size=22),
axis.title = element_text(size=24)) +
scale_fill_manual(name = "Environments", values=c("#27AE60",
"#CACFD2",
"#F0F3F4"))
set.seed(123)
filter(signature, signature == "nps")%>%
ggplot(aes(x = condition, y = value_stand, fill = condition)) +
geom_violin(adjust = 1, linewidth = 1) +
geom_boxplot(width = 0.2, outlier.shape = NA, linewidth = 1) +
geom_jitter(width = 0.15, height = 0.05, colour = "#979797",size = 0.8) +
xlab("Environment") + ylab("Standardized NPS score") +
ggtitle("NPS") +
scale_y_continuous(limits = c(-3, 5), breaks=c(-2, 0, 2, 4)) +
stat_summary(fun=mean,shape=19,col="#CB4335", geom='point', size = 2) +
scale_x_discrete(labels=c("Nature","Urban","Indoor")) +
theme(plot.title = element_text(size=24, face = "bold", hjust = 0.5, family = "Arial"),
legend.position = "none",
strip.text = element_text(size=22),
axis.text = element_text(size=22),
axis.title = element_text(size=24)) +
scale_fill_manual(name = "Environments", values=c("#27AE60",
"#CACFD2",
"#F0F3F4"))
set.seed(321)
filter(signature, signature == "siips")%>%
ggplot(aes(x = condition, y = value_stand, fill = condition)) +
geom_violin(adjust = 1, linewidth = 1) +
geom_boxplot(width = 0.2, outlier.shape = NA, linewidth = 1) +
geom_jitter(width = 0.15, height = 0.05, colour = "#979797",size = 0.8) +
xlab("Environment") + ylab("Standardized SIIPS1 score") +
ggtitle("SIIPS1") +
scale_y_continuous(limits = c(-3, 5), breaks=c(-2, 0, 2, 4)) +
stat_summary(fun=mean,shape=19,col="#CB4335", geom='point', size = 2) +
scale_x_discrete(labels=c("Nature","Urban","Indoor")) +
theme(plot.title = element_text(size=24, face = "bold", hjust = 0.5, family = "Arial"),
legend.position = "none",
strip.text = element_text(size=22),
axis.text = element_text(size=22),
axis.title = element_text(size=24)) +
scale_fill_manual(name = "Environments", values=c("#27AE60",
"#CACFD2",
"#F0F3F4"))
library(readr)
library(tidyverse)
library(ggplot2)
# set your home directory
home_dir = "/Users/max/Documents/Dissertation/Study 1 - Nature Pain MRI/Data & Analyses/Upload/Final_Upload/Additional_Correlations"
# define file paths
roi_path = file.path(home_dir, "roi_allreg.csv")
# create dataframe
roi = as.data.frame(read_delim(roi_path, col_names = TRUE, delim = ",", show_col_types = FALSE))
roi_temp = roi %>%
mutate(region_grouped = case_when(
region %in% c("lThal", "rThal") ~ "Thalamus",
region %in% c("lS1", "rS1") ~ "S1",
region %in% c("lS2", "rS2") ~ "S2",
region %in% c("lAMY", "rAMY") ~ "Amygdala",
region %in% c("laINS", "raINS") ~ "aINS",
region %in% c("lpINS", "rpINS") ~ "pINS",
region %in% c("lSPL", "rSPL") ~ "SPL",
TRUE ~ region
))
roi_summary = roi_temp %>%
group_by(region_grouped, condition, subject) %>%
summarise(
mean_value = mean(value, na.rm = TRUE),
se_value = sd(value, na.rm = TRUE) / sqrt(49)
)
set.seed(213)
# ascending pathway ROIs
ascending_rois = roi_summary %>%
filter(region_grouped %in% c("S1", "Thalamus"))
summary_ascending = ascending_rois %>%
group_by(region_grouped, condition) %>%
summarise(
means = mean(mean_value),
se = sd(mean_value) / sqrt(n()),
.groups = "drop"
)
set.seed(213)
# ascending pathway ROIs
ascending_rois = roi_summary %>%
filter(region_grouped %in% c("S1", "Thalamus"))
summary_ascending = ascending_rois %>%
group_by(region_grouped, condition) %>%
summarise(
means = mean(mean_value),
se = sd(mean_value) / sqrt(n()),
.groups = "drop"
)
# plot figure
ggplot(summary_ascending, aes(x = region_grouped, y = means, fill = condition)) +
# Bar plot for means
geom_bar(stat = "identity",
position = position_dodge(width = 0.9),
width = 0.8,
color = "black") +
# Error bars for standard error
geom_errorbar(aes(ymin = means - se, ymax = means + se),
position = position_dodge(width = 0.9),
width = 0.25) +
# Individual points for each participant
geom_point(data = ascending_rois,
aes(x = region_grouped, y = mean_value, color = condition),
color = '#B0B0B0',
position = position_jitterdodge(dodge.width = 0.9, jitter.width = 0.2),
size = 2, alpha = 0.7) +
# Labels and title
labs(x = "Region of Interest (ROI)", y = "Mean ROI Response + S.E.M. (a.u.)",
title = "Ascending Pathway") +
# Custom color scheme
scale_fill_manual(name = "Environments", values = c("#27AE60", "#CACFD2", "#F0F3F4")) +
# Theme adjustments
theme_minimal() +
theme(
plot.title = element_text(face = "bold", size = 16, hjust = 0.5),
axis.title = element_text(size = 14),
axis.text = element_text(size = 14),
axis.text.x = element_text(angle = 0, hjust = 0.5),
plot.background = element_rect(fill = "gray98", color = NA),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "none"
)
set.seed(321)
# descending pathway (attention) ROIs
attention_rois = roi_summary %>%
filter(region_grouped %in% c("S2", "pINS", "SPL", "Amygdala"))
summary_attention = attention_rois %>%
group_by(region_grouped, condition) %>%
summarise(
means = mean(mean_value),
se = sd(mean_value) / sqrt(n()),  # Standard error of the mean
.groups = "drop"
)
# plot figure
ggplot(summary_attention, aes(x = region_grouped, y = means, fill = condition)) +
# Bar plot for means
geom_bar(stat = "identity",
position = position_dodge(width = 0.9),
width = 0.8,
color = "black") +
# Error bars for standard error
geom_errorbar(aes(ymin = means - se, ymax = means + se),
position = position_dodge(width = 0.9),
width = 0.25) +
# Individual points for each participant
geom_point(data = attention_rois,
aes(x = region_grouped, y = mean_value, color = condition),
color = '#B0B0B0',
position = position_jitterdodge(dodge.width = 0.9, jitter.width = 0.2),
size = 2, alpha = 0.7) +
# Labels and title
labs(x = "Region of Interest (ROI)", y = "Mean ROI Response + S.E.M. (a.u.)",
title = "Descending Pathway (Attention)") +
# Custom color scheme
scale_fill_manual(name = "Environments", values = c("#27AE60", "#CACFD2", "#F0F3F4")) +
# Theme adjustments
theme_minimal() +
theme(
plot.title = element_text(face = "bold", size = 16, hjust = 0.5),
axis.title = element_text(size = 14),
axis.text = element_text(size = 14),
axis.text.x = element_text(angle = 0, hjust = 0.5),
plot.background = element_rect(fill = "gray98", color = NA),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "none"
)
set.seed(123)
# descending pathway (emotion) ROIs
emotion_rois =  roi_summary %>%
filter(region_grouped %in% c("aINS", "mPFC", "aMCC", "PAG"))
summary_emotion = emotion_rois %>%
group_by(region_grouped, condition) %>%
summarise(
means = mean(mean_value),
se = sd(mean_value) / sqrt(n()),
.groups = "drop"
)
# plot figure
ggplot(summary_emotion, aes(x = region_grouped, y = means, fill = condition)) +
# Bar plot for means
geom_bar(stat = "identity",
position = position_dodge(width = 0.9),
width = 0.8,
color = "black") +
# Error bars for standard error
geom_errorbar(aes(ymin = means - se, ymax = means + se),
position = position_dodge(width = 0.9),
width = 0.25) +
# Individual points for each participant
geom_point(data = emotion_rois,
aes(x = region_grouped, y = mean_value, color = condition),
color = '#B0B0B0',
position = position_jitterdodge(dodge.width = 0.9, jitter.width = 0.2),
size = 2, alpha = 0.7) +
# Labels and title
labs(x = "Region of Interest (ROI)", y = "Mean ROI Response + S.E.M. (a.u.)",
title = "Descending Pathway (Emotion)") +
# Custom color scheme
scale_fill_manual(name = "Environments", values = c("#27AE60", "#CACFD2", "#F0F3F4")) +
# Theme adjustments
theme_minimal() +
theme(
plot.title = element_text(face = "bold", size = 16, hjust = 0.5),
axis.title = element_text(size = 14),
axis.text = element_text(size = 14),
axis.text.x = element_text(angle = 0, hjust = 0.5),
plot.background = element_rect(fill = "gray98", color = NA),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "none"
)
