R Under development (unstable) (2024-10-10 r87224 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # Load necessary libraries > library(diceplot) > library(tidyr) > library(data.table) > library(ggplot2) > library(dplyr) Attaching package: 'dplyr' The following objects are masked from 'package:data.table': between, first, last The following objects are masked from 'package:stats': filter, lag The following objects are masked from 'package:base': intersect, setdiff, setequal, union > library(tibble) > library(grid) > library(cowplot) > > plot_path = "sample_plots" > > # Define the variables and their colors for 3 variables > pathology_variables <- c("Amyloid", "NFT", "Tangles") > cat_c_colors <- c( + "Amyloid" = "#d5cccd", + "NFT" = "#cb9992", + "Tangles" = "#ad310f" + ) > > # Define cell types (cat_a) > cell_types <- c("Neuron", "Astrocyte", "Microglia", "Oligodendrocyte", "Endothelial") > > # Define pathways (cat_b) and groups > pathways <- c( + "Apoptosis", "Inflammation", "Metabolism", "Signal Transduction", "Synaptic Transmission", + "Cell Cycle", "DNA Repair", "Protein Synthesis", "Lipid Metabolism", "Neurotransmitter Release" + ) > > # Assign groups to pathways > pathway_groups <- data.frame( + Pathway = pathways, + Group = c( + "BBB-linked", "Cell-proliferation", "Other", "BBB-linked", "Cell-proliferation", + "Cell-proliferation", "Other", "Other", "Other", "BBB-linked" + ), + stringsAsFactors = FALSE + ) > > # Define group colors > group_colors <- c( + "BBB-linked" = "#333333", + "Cell-proliferation" = "#888888", + "Other" = "#DDDDDD" + ) > > # Create dummy data > set.seed(123) > data <- expand.grid(CellType = cell_types, Pathway = pathways, stringsAsFactors = FALSE) > > # Assign random pathology variables to each combination > data <- data %>% + rowwise() %>% + mutate( + PathologyVariable = list(sample(pathology_variables, size = sample(1:3, 1))) + ) %>% + unnest(cols = c(PathologyVariable)) > > # Merge the group assignments into the data > data <- data %>% + left_join(pathway_groups, by = c("Pathway" = "Pathway")) > > # Use the dice_plot function > dice_plot(data = data, + cat_a = "CellType", + cat_b = "Pathway", + cat_c = "PathologyVariable", + group = "Group", + plot_path = plot_path, + output_str = "dice_plot_3_example", + group_alpha = 0.6, + title = "Dice Plot with 3 Pathology Variables", + cat_c_colors = cat_c_colors, + group_colors = group_colors, + format = ".png", + custom_theme = theme_minimal()) [1] 3 ✔ Created directory: 'sample_plots'. > > > > # Define the pathology variables and their colors > pathology_variables <- c("Amyloid", "NFT", "Tangles", "Plaq N") > cat_c_colors <- c( + "Amyloid" = "#d5cccd", + "NFT" = "#cb9992", + "Tangles" = "#ad310f", + "Plaq N" = "#7e2a20" + ) > > # Define cell types (cat_a) > cell_types <- c("Neuron", "Astrocyte", "Microglia", "Oligodendrocyte", "Endothelial") > > # Define pathways (cat_b) and add 10 more to make a total of 15 > pathways <- c( + "Apoptosis", "Inflammation", "Metabolism", "Signal Transduction", "Synaptic Transmission", + "Cell Cycle", "DNA Repair", "Protein Synthesis", "Lipid Metabolism", "Neurotransmitter Release", + "Oxidative Stress", "Energy Production", "Calcium Signaling", "Synaptic Plasticity", "Immune Response" + ) > > # Assign groups to pathways (ensuring each pathway has only one group) > pathway_groups <- data.frame( + Pathway = pathways, + Group = c( + "BBB-linked", "Cell-proliferation", "Other", "BBB-linked", "Cell-proliferation", + "Cell-proliferation", "Other", "Other", "Other", "BBB-linked", + "Other", "Other", "BBB-linked", "Cell-proliferation", "Other" + ), + stringsAsFactors = FALSE + ) > > # Update group colors to shades of greys > group_colors <- c( + "BBB-linked" = "#333333", + "Cell-proliferation" = "#888888", + "Other" = "#DDDDDD" + ) > > # Create dummy data > set.seed(123) > data <- expand.grid(CellType = cell_types, Pathway = pathways, stringsAsFactors = FALSE) > > # Assign random pathology variables to each combination > data <- data %>% + rowwise() %>% + mutate( + PathologyVariable = list(sample(pathology_variables, size = sample(1:4, 1))) + ) %>% + unnest(cols = c(PathologyVariable)) > > # Merge the group assignments into the data > data <- data %>% + left_join(pathway_groups, by = "Pathway") > > group_colors <- c( + "BBB-linked" = "#333333", + "Cell-proliferation" = "#888888", + "Other" = "#DDDDDD" + ) > # Use the modified dice_plot function > dice_plot(data = data, + cat_a = "CellType", + cat_b = "Pathway", + cat_c = "PathologyVariable", + group = "Group", + plot_path = plot_path, + output_str = "dice_plot_4_example", + group_alpha = 0.6, + title = "Dummy Dice Plot with Pathology Variables", + cat_c_colors = cat_c_colors, + group_colors = group_colors, + format = ".png", + custom_theme = theme_minimal()) [1] 4 > > > # Define the variables and their colors for 5 variables > pathology_variables <- c("Amyloid", "NFT", "Tangles", "Plaq N", "Var5") > cat_c_colors <- c( + "Amyloid" = "#d5cccd", + "NFT" = "#cb9992", + "Tangles" = "#ad310f", + "Plaq N" = "#7e2a20", + "Var5" = "#FFD700" # Gold color for Var5 + ) > > # Create dummy data > set.seed(123) > data <- expand.grid(CellType = cell_types, Pathway = pathways, stringsAsFactors = FALSE) > > # Assign random pathology variables to each combination > data <- data %>% + rowwise() %>% + mutate( + PathologyVariable = list(sample(pathology_variables, size = sample(1:5, 1))) + ) %>% + unnest(cols = c(PathologyVariable)) > > # Merge the group assignments into the data > data <- data %>% + left_join(pathway_groups, by = c("Pathway" = "Pathway")) > > # Use the dice_plot function > dice_plot(data = data, + cat_a = "CellType", + cat_b = "Pathway", + cat_c = "PathologyVariable", + group = "Group", + plot_path = plot_path, + output_str = "dice_plot_5_example", + group_alpha = 0.6, + title = "Dice Plot with 5 Pathology Variables", + cat_c_colors = cat_c_colors, + group_colors = group_colors, + format = ".png", + custom_theme = theme_minimal()) [1] 5 > > > # Define the variables and their colors for 6 variables > pathology_variables <- c("Amyloid", "NFT", "Tangles", "Plaq N", "Age", "Weight") > cat_c_colors <- c( + "Amyloid" = "#d5cccd", + "NFT" = "#cb9992", + "Tangles" = "#ad310f", + "Plaq N" = "#7e2a20", + "Age" = "#FFD700", # Gold color for Var5 + "Weight" = "#FF6622" # Cyan color for Var6 + ) > > # Create dummy data > set.seed(123) > data <- expand.grid(CellType = cell_types, Pathway = pathways, stringsAsFactors = FALSE) > > # Assign random pathology variables to each combination > data <- data %>% + rowwise() %>% + mutate( + PathologyVariable = list(sample(pathology_variables, size = sample(1:6, 1))) + ) %>% + unnest(cols = c(PathologyVariable)) > > # Merge the group assignments into the data > data <- data %>% + left_join(pathway_groups, by = c("Pathway" = "Pathway")) > > # Use the dice_plot function > dice_plot(data = data, + cat_a = "CellType", + cat_b = "Pathway", + cat_c = "PathologyVariable", + group = "Group", + plot_path = plot_path, + output_str = "dice_plot_6_example", + group_alpha = 0.6, + title = "Dice Plot with 6 Pathology Variables", + cat_c_colors = cat_c_colors, + group_colors = group_colors, + format = ".png", + custom_theme = theme_minimal()) [1] 6 > > > proc.time() user system elapsed 6.78 0.57 7.35