2626# ' set.seed(2025)
2727# ' results <- load_example_results()
2828# ' results <- results[sample(seq(nrow(results)), 5000),]
29- # ' out <- plot_celltype_severity(results, types="bar")
29+ # ' out <- plot_celltype_severity(results, types=c( "bar","dot") )
3030plot_celltype_severity <- function (results ,
3131 cl = get_cl(),
3232 q_threshold = .05 ,
@@ -64,9 +64,14 @@ plot_celltype_severity <- function(results,
6464 " blindness" ," sensory_impairments" ," immunodeficiency" ," cancer" ,
6565 " reduced_fertility" ," congenital_onset" )]| >
6666 data.table :: melt.data.table(id.vars = c(" cl_id" ," cl_name" ))
67+
6768 )[,value : = factor (value ,levels = c(0 : 3 ),ordered = TRUE )]
69+
70+ # Split variable names for plotting
6871 agg_gpt [,variable : = gsub(" _" ," " ,variable )]
69- agg_gpt [,variable : = factor (variable , levels = unique(variable ),ordered = TRUE )]
72+ agg_gpt [,variable_split : = gsub(" " ," \n " ,variable )]
73+ agg_gpt [variable_split == " immunodeficiency" ,variable_split : = " immuno-\n deficiency" ]
74+ agg_gpt [,variable_split : = factor (variable_split , levels = unique(variable_split ),ordered = TRUE )]
7075 # Set celltype name order
7176 agg_gpt [,cl_name : = factor (cl_name , levels = celltype_order ,ordered = TRUE )]
7277
@@ -80,6 +85,8 @@ plot_celltype_severity <- function(results,
8085 out <- list ()
8186 if (" bar" %in% types ){
8287 messager(" Creating bar plot." )
88+
89+ # Subplot with composite severity scores
8390 gg_severity <- ggplot2 :: ggplot(celltypes_gpt ,
8491 ggplot2 :: aes(x = cl_name ,y = severity_score_gpt ,
8592 fill = severity_score_gpt )) +
@@ -89,9 +96,11 @@ plot_celltype_severity <- function(results,
8996 fill = " GPT\n severity\n score" ) +
9097 ggplot2 :: coord_flip()+
9198 ggplot2 :: theme_minimal()
99+
100+ # Subplot with individual severity annotations
92101 gg_annot <- ggplot2 :: ggplot(agg_gpt [! is.na(value )],
93102 ggplot2 :: aes(x = cl_name , y = 1 , fill = value ))+
94- ggplot2 :: facet_grid(. ~ variable , scales = " free_y" )+
103+ ggplot2 :: facet_grid(. ~ variable_split , scales = " free_y" )+
95104 ggplot2 :: geom_bar(stat = " identity" , position = " fill" )+
96105 ggplot2 :: scale_fill_viridis_d(option = " plasma" ,
97106 labels = c(`0` = " never" ,
@@ -101,7 +110,8 @@ plot_celltype_severity <- function(results,
101110 ggplot2 :: scale_y_continuous(breaks = c(0 ,.5 ,1 ), labels = c(" 0" ," 0.5" ," 1" )) +
102111 ggplot2 :: labs(y = " Proportion of associated phenotypes" , x = " Cell type" ) +
103112 ggplot2 :: coord_flip()+
104- ggplot2 :: theme_minimal()
113+ ggplot2 :: theme_minimal() +
114+ ggplot2 :: theme(axis.text.x = ggplot2 :: element_text(vjust = 1 ) )
105115
106116 out [[" bar" ]][[" plot" ]] <- (gg_annot | gg_severity ) +
107117 patchwork :: plot_layout(axes = " collect" , widths = c(1 ,.1 ))
0 commit comments