First, we load necessary R libraries.
library(data.table)
library(janitor)
library(dplyr)
library(ggpubr)
library(pals)
library(openxlsx)
options(stringsAsFactors = F,max.print = 10000,error=NULL,
"openxlsx.dateFormat" = "dd/mm/yyyy"
)
Then, we load the data source necessary to generate all the figures.
##load data source
df <- openxlsx::read.xlsx("../../Revision/Results/Longitudinal_meth_data/Data_source_methylation_Fig.4_SCLL12-SCLL19.xlsx")
We loop over the cases and plot
for(case.i in unique(df$case)){
p <-
df %>%
filter(case==case.i) %>%
mutate(cpgs_diff_abs=case_when(cpgs_diff_abs>= 0.25 ~ 0.25,
.default = cpgs_diff_abs
)
) %>%
ggplot(aes(x=meth.T2,
y=meth.T1,
fill=cpgs_diff_abs
)
)+
geom_point(pch=21,stroke=0.1,size=0.6)+
scale_fill_gradientn("Absolute methylation\ndifference",
colours = viridis(100) %>% rev()
)+
facet_grid(~comparison)+
theme_classic()+
theme(text = element_text(colour = "grey0",size = 5),
panel.grid.major = element_line(linewidth = 0.075),
# panel.grid.minor.x = element_line(linewidth = 0.025),
strip.placement = "out",
strip.background = element_blank(),
strip.text = element_text(angle = 0),
plot.margin = unit(c(0,0,0,0),"pt"),
line=element_line(linewidth = 0.1),
legend.position = "bottom",
legend.box.margin=margin(-5,-5,-5,-5),
# legend.justification="top",
legend.text = element_text(angle = 90,vjust = 0.5,hjust = 0.5),
plot.background =element_blank(),
legend.key.size = unit(5,"pt")
)
print(p)
}
print(sessionInfo())
## R version 4.5.0 (2025-04-11)
## Platform: aarch64-apple-darwin20
## Running under: macOS Ventura 13.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: Europe/Madrid
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] openxlsx_4.2.8 pals_1.10 ggpubr_0.6.1 ggplot2_3.5.2
## [5] dplyr_1.1.4 janitor_2.2.1 data.table_1.17.8 BiocStyle_2.36.0
##
## loaded via a namespace (and not attached):
## [1] sass_0.4.10 generics_0.1.4 tidyr_1.3.1
## [4] rstatix_0.7.2.999 stringi_1.8.7 digest_0.6.37
## [7] magrittr_2.0.3 evaluate_1.0.5 grid_4.5.0
## [10] timechange_0.3.0 RColorBrewer_1.1-3 bookdown_0.44
## [13] maps_3.4.3 fastmap_1.2.0 jsonlite_2.0.0
## [16] zip_2.3.3 backports_1.5.0 Formula_1.2-5
## [19] tinytex_0.57 BiocManager_1.30.26 purrr_1.1.0
## [22] scales_1.4.0 jquerylib_0.1.4 abind_1.4-8
## [25] cli_3.6.5 rlang_1.1.6 withr_3.0.2
## [28] cachem_1.1.0 yaml_2.3.10 tools_4.5.0
## [31] ggsignif_0.6.4 colorspace_2.1-1 broom_1.0.9
## [34] mapproj_1.2.12 vctrs_0.6.5 R6_2.6.1
## [37] magick_2.8.7 lifecycle_1.0.4 lubridate_1.9.4
## [40] snakecase_0.11.1 stringr_1.5.1 car_3.1-3
## [43] pkgconfig_2.0.3 pillar_1.11.0 bslib_0.9.0
## [46] gtable_0.3.6 Rcpp_1.1.0 glue_1.8.0
## [49] xfun_0.53 tibble_3.3.0 tidyselect_1.2.1
## [52] rstudioapi_0.17.1 knitr_1.50 dichromat_2.0-0.1
## [55] farver_2.1.2 htmltools_0.5.8.1 labeling_0.4.3
## [58] rmarkdown_2.29 carData_3.0-5 compiler_4.5.0