library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## Warning: package 'tidyr' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0.9000     ✔ stringr   1.5.1     
## ✔ lubridate 1.9.3          ✔ tibble    3.2.1     
## ✔ purrr     1.0.2          ✔ tidyr     1.3.1     
## ✔ readr     2.1.5
## ── 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
library(RColorBrewer)
library(ggpubr)
library(ComplexHeatmap)
## Warning: package 'ComplexHeatmap' was built under R version 4.3.1
## Loading required package: grid
## ========================================
## ComplexHeatmap version 2.18.0
## Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
## Github page: https://github.com/jokergoo/ComplexHeatmap
## Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
## 
## If you use it in published research, please cite either one:
## - Gu, Z. Complex Heatmap Visualization. iMeta 2022.
## - Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
##     genomic data. Bioinformatics 2016.
## 
## 
## The new InteractiveComplexHeatmap package can directly export static 
## complex heatmaps into an interactive Shiny app with zero effort. Have a try!
## 
## This message can be suppressed by:
##   suppressPackageStartupMessages(library(ComplexHeatmap))
## ========================================
library(pheatmap)
## 
## Attaching package: 'pheatmap'
## 
## The following object is masked from 'package:ComplexHeatmap':
## 
##     pheatmap
library(readxl)
Timepoint.1.8 <- read_excel("~/Desktop/Directionality-new.xlsx", sheet = 1)
head(Timepoint.1.8)
## # A tibble: 6 × 4
##   Brain-CSF 1.8months Co…¹ `MeanDif Brain WT-FAD` `MeanDif CSF WT-FAD` Direction
##   <chr>                                     <dbl>                <dbl> <chr>    
## 1 GOBP_REGULATION_OF_FATT…                -0.236                -0.417 Concorda…
## 2 GOBP_POSITIVE_REGULATIO…                -0.311                -0.452 Discorda…
## 3 GOMF_HYDROLASE_ACTIVITY…                -0.0296               -0.159 Discorda…
## 4 GOBP_POSITIVE_REGULATIO…                 0.525                 0.374 Concorda…
## 5 GOBP_NEGATIVE_REGULATIO…                -0.351                -0.452 Discorda…
## 6 GOBP_HEPATIC_STELLATE_C…                -0.353                -0.568 Discorda…
## # ℹ abbreviated name: ¹​`Brain-CSF 1.8months Common pathways`
colnames(Timepoint.1.8) <- c('Pathway', 'MeanDif_Brain_WT_FAD', 'MeanDif_CSF_WT_FAD', 'Direction')
head(Timepoint.1.8)
## # A tibble: 6 × 4
##   Pathway                      MeanDif_Brain_WT_FAD MeanDif_CSF_WT_FAD Direction
##   <chr>                                       <dbl>              <dbl> <chr>    
## 1 GOBP_REGULATION_OF_FATTY_AC…              -0.236              -0.417 Concorda…
## 2 GOBP_POSITIVE_REGULATION_OF…              -0.311              -0.452 Discorda…
## 3 GOMF_HYDROLASE_ACTIVITY_ACT…              -0.0296             -0.159 Discorda…
## 4 GOBP_POSITIVE_REGULATION_OF…               0.525               0.374 Concorda…
## 5 GOBP_NEGATIVE_REGULATION_OF…              -0.351              -0.452 Discorda…
## 6 GOBP_HEPATIC_STELLATE_CELL_…              -0.353              -0.568 Discorda…
data <- Timepoint.1.8
# Convert Direction to a factor
data$Direction <- as.factor(data$Direction)
# Reshape the data for plotting
data_long <- data %>%
  pivot_longer(cols = c(MeanDif_Brain_WT_FAD, MeanDif_CSF_WT_FAD), 
               names_to = "Condition", 
               values_to = "Value") %>%
  mutate(Condition = ifelse(Condition == "MeanDif_Brain_WT_FAD", "Brain WT-FAD", "CSF WT-FAD"))

# Write the reshaped data to a CSV file
write.csv(data_long, file = 'data_long.timepoint.1.8.brain.vs.csf.csv')
# Create a bar plot
gg <- ggplot(data_long, aes(x = Value, y = Pathway, fill = Direction)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("Concordant" = "navy", "Discordant" = "brown")) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  labs(title = "Brain vs. CSF for Timepoint 1.8 months",
       x = "Mean Difference",
       y = "Pathway",
       fill = "Direction") +
  theme_minimal() +
  theme(
    axis.text.y = element_text(size = 7, face = "bold"),
    axis.title.x = element_text(face = "bold"),
    axis.title.y = element_text(face = "bold"),
    plot.title = element_text(face = "bold")
  )
# Print the plot
print(gg)

gg

Timepoint.3mon <- read_excel("~/Desktop/Directionality-new.xlsx", sheet = 2)
Timepoint.3mon <- as.data.frame(Timepoint.3mon)
colnames(Timepoint.3mon) <- c('Pathway', 'MeanDif_Brain_WT_FAD', 'MeanDif_CSF_WT_FAD', 'Direction')
data <- Timepoint.3mon
# Convert Direction to a factor
data$Direction <- as.factor(data$Direction)
# Reshape the data for plotting
data_long <- data %>%
  pivot_longer(cols = c(MeanDif_Brain_WT_FAD, MeanDif_CSF_WT_FAD), 
               names_to = "Condition", 
               values_to = "Value") %>%
  mutate(Condition = ifelse(Condition == "MeanDif_Brain_WT_FAD", "Brain WT-FAD", "CSF WT-FAD"))
# Write the reshaped data to a CSV file
write.csv(data_long, file = 'data_long.timepoint.3Months.brain.vs.csf.csv')
# Create a bar plot
gg <- ggplot(data_long, aes(x = Value, y = Pathway, fill = Direction)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("Concordant" = "navy", "Discordant" = "brown")) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  labs(title = "Brain vs. CSF for Timepoint 3-months",
       x = "Mean Difference",
       y = "Pathway",
       fill = "Direction") +
  theme_minimal() +
  theme(
    axis.text.y = element_text(size = 7, face = "bold"),
    axis.title.x = element_text(face = "bold"),
    axis.title.y = element_text(face = "bold"),
    plot.title = element_text(face = "bold")
  )
# Print the plot
print(gg)

gg

#Timepoint.6mon <- read_excel("~/Desktop/Directionality-new.xlsx", sheet = 3)
Timepoint_6months_deleted_gsva <- read_excel("Timepoint.6months.deleted.gsva.xlsx")
Timepoint.6mon <- as.data.frame(Timepoint_6months_deleted_gsva)
colnames(Timepoint.6mon) <- c('Pathway', 'MeanDif_Brain_WT_FAD', 'MeanDif_CSF_WT_FAD', 'Direction.old', 'Direction')
data <- Timepoint.6mon
# Convert Direction to a factor
data$Direction <- as.factor(data$Direction)
# Reshape the data for plotting
data_long <- data %>%
  pivot_longer(cols = c(MeanDif_Brain_WT_FAD, MeanDif_CSF_WT_FAD), 
               names_to = "Condition", 
               values_to = "Value") %>%
  mutate(Condition = ifelse(Condition == "MeanDif_Brain_WT_FAD", "Brain WT-FAD", "CSF WT-FAD"))
# Write the reshaped data to a CSV file
write.csv(data_long, file = 'data_long.timepoint.6_Months.brain.vs.csf.csv')
# Create a bar plot
gg <- ggplot(data_long, aes(x = Value, y = Pathway, fill = Direction)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("Concordant" = "navy", "Discordant" = "brown")) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  labs(title = "Brain vs. CSF for Timepoint 6-months",
       x = "Mean Difference",
       y = "Pathway",
       fill = "Direction") +
  theme_minimal() +
  theme(
    axis.text.y = element_text(size = 7, face = "bold"),
    axis.title.x = element_text(face = "bold"),
    axis.title.y = element_text(face = "bold"),
    plot.title = element_text(face = "bold")
  )
# Print the plot
print(gg)

gg

Timepoint.10mon <- read_excel("GSVA.10Months.xlsx")
Timepoint.10mon <- as.data.frame(Timepoint.10mon)
colnames(Timepoint.10mon) <- c('Pathway', 'MeanDif_Brain_WT_FAD', 'MeanDif_CSF_WT_FAD', 'Direction.old', 'Direction')
data <- Timepoint.10mon
# Convert Direction to a factor
data$Direction <- as.factor(data$Direction)
# Reshape the data for plotting
data_long <- data %>%
  pivot_longer(cols = c(MeanDif_Brain_WT_FAD, MeanDif_CSF_WT_FAD), 
               names_to = "Condition", 
               values_to = "Value") %>%
  mutate(Condition = ifelse(Condition == "MeanDif_Brain_WT_FAD", "Brain WT-FAD", "CSF WT-FAD"))
# Write the reshaped data to a CSV file
write.csv(data_long, file = 'data_long.timepoint.10_Months.brain.vs.csf.csv')
# Create a bar plot
gg <- ggplot(data_long, aes(x = Value, y = Pathway, fill = Direction)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("Concordant" = "navy", "Discordant" = "brown")) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  labs(title = "Brain vs. CSF for Timepoint 10-months",
       x = "Mean Difference",
       y = "Pathway",
       fill = "Direction") +
  theme_minimal() +
  theme(
    axis.text.y = element_text(size = 7, face = "bold"),
    axis.title.x = element_text(face = "bold"),
    axis.title.y = element_text(face = "bold"),
    plot.title = element_text(face = "bold")
  )
# Print the plot
print(gg)

gg

Timepoint.14Months <- read_excel("Timepoint.14.Months.xlsx")
Timepoint.14Months <- as.data.frame(Timepoint.14Months)
colnames(Timepoint.14Months) <- c('Pathway', 'MeanDif_Brain_WT_FAD', 'MeanDif_CSF_WT_FAD', 'Direction.old', 'Direction')
data <- Timepoint.14Months
# Convert Direction to a factor
data$Direction <- as.factor(data$Direction)
# Reshape the data for plotting
data_long <- data %>%
  pivot_longer(cols = c(MeanDif_Brain_WT_FAD, MeanDif_CSF_WT_FAD), 
               names_to = "Condition", 
               values_to = "Value") %>%
  mutate(Condition = ifelse(Condition == "MeanDif_Brain_WT_FAD", "Brain WT-FAD", "CSF WT-FAD"))
# Write the reshaped data to a CSV file
write.csv(data_long, file = 'data_long.timepoint.14_Months.brain.vs.csf.csv')
# Create a bar plot
gg <- ggplot(data_long, aes(x = Value, y = Pathway, fill = Direction)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("Concordant" = "navy", "Discordant" = "brown")) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  labs(title = "Brain vs. CSF for Timepoint 14-months",
       x = "Mean Difference",
       y = "Pathway",
       fill = "Direction") +
  theme_minimal() +
  theme(
    axis.text.y = element_text(size = 7, face = "bold"),
    axis.title.x = element_text(face = "bold"),
    axis.title.y = element_text(face = "bold"),
    plot.title = element_text(face = "bold")
  )
# Print the plot
print(gg)

gg