@@ -571,13 +571,15 @@ plot_ccdist <- function(object, celltype_sender, celltype_receiver, color = NULL
571571# ' @param type Set 'sig' to plot significant LR pairs or set 'number' to plot the number of spatial LR interactions.
572572# ' @param fontsize_number fontsize of the numbers displayed in cells.
573573# ' @param number_color color of the text.
574- # ' @import ggplot2 pheatmap
574+ # ' @param color_low For 'number' type, define the color for the lowest value.
575+ # ' @param color_high For 'number' type, define the color for the highest value.
576+ # ' @import ggplot2 pheatmap grDevices
575577# ' @importFrom ggpubr get_palette
576578# ' @importFrom reshape2 dcast
577579# ' @export
578580
579- plot_cci_lrpairs <- function (object , celltype_sender , celltype_receiver , top_lrpairs = 20 , color = NULL ,
580- border_color = " black " , type = NULL , fontsize_number = 1 , number_color = " black " ) {
581+ plot_cci_lrpairs <- function (object , celltype_sender , celltype_receiver , top_lrpairs = 20 , color = NULL , border_color = " black " , type = " sig " ,
582+ fontsize_number = 5 , number_color = " black " , color_low = NULL , color_high = NULL ) {
581583 # check
582584 if (! is(object , " SpaTalk" )) {
583585 stop(" Invalid class for object: must be 'SpaTalk'!" )
@@ -624,25 +626,41 @@ plot_cci_lrpairs <- function(object, celltype_sender, celltype_receiver, top_lrp
624626 }
625627 ligand <- unique(lrpair $ ligand )
626628 receptor <- unique(lrpair $ receptor )
627- # get lrpair_real
628- lrpair_real <- object @ lr_path $ lrpairs
629- lrpair_real <- lrpair_real [, c(1 , 2 )]
630- lrpair_real $ score <- 1
631- lrpair_mat <- reshape2 :: dcast(lrpair_real , formula = ligand ~ receptor , fill = 0 , value.var = " score" )
632- rownames(lrpair_mat ) <- lrpair_mat $ ligand
633- lrpair_mat <- lrpair_mat [, - 1 ]
634- lrpair_mat <- lrpair_mat [ligand , receptor ]
635- if (! is.data.frame(lrpair_mat )) {
636- stop(" Limited number of ligand-receptor interactions!" )
637- }
638- plot_res <- matrix (" " , nrow = length(ligand ), ncol = length(receptor ))
639- rownames(plot_res ) <- ligand
640- colnames(plot_res ) <- receptor
641- for (i in 1 : nrow(lrpair )) {
642- plot_res [lrpair $ ligand [i ], lrpair $ receptor [i ]] <- " *"
643- }
644- pheatmap :: pheatmap(lrpair_mat , cluster_cols = F , cluster_rows = F , color = heat_col , border_color = border_color ,
645- legend = F , display_numbers = plot_res , fontsize_number = fontsize_number , number_color = number_color )
629+ if (type == " sig" ) {
630+ # get lrpair_real
631+ lrpair_real <- object @ lr_path $ lrpairs
632+ lrpair_real <- lrpair_real [, c(1 , 2 )]
633+ lrpair_real $ score <- 1
634+ lrpair_mat <- reshape2 :: dcast(lrpair_real , formula = ligand ~ receptor , fill = 0 , value.var = " score" )
635+ rownames(lrpair_mat ) <- lrpair_mat $ ligand
636+ lrpair_mat <- lrpair_mat [, - 1 ]
637+ lrpair_mat <- lrpair_mat [ligand , receptor ]
638+ if (! is.data.frame(lrpair_mat )) {
639+ stop(" Limited number of ligand-receptor interactions!" )
640+ }
641+ plot_res <- matrix (" " , nrow = length(ligand ), ncol = length(receptor ))
642+ rownames(plot_res ) <- ligand
643+ colnames(plot_res ) <- receptor
644+ for (i in 1 : nrow(lrpair )) {
645+ plot_res [lrpair $ ligand [i ], lrpair $ receptor [i ]] <- " *"
646+ }
647+ pheatmap :: pheatmap(lrpair_mat , cluster_cols = F , cluster_rows = F , color = heat_col , border_color = border_color , legend = F , display_numbers = plot_res ,
648+ fontsize_number = fontsize_number , number_color = number_color , main = " Significantly enriched LRI" )
649+ } else {
650+ if (is.null(color_low )) {
651+ color_low <- " orange"
652+ }
653+ if (is.null(color_high )) {
654+ color_high <- " red"
655+ }
656+ lrpair_real <- lrpair [,c(" ligand" ," receptor" ," lr_co_exp_num" )]
657+ lrpair_mat <- reshape2 :: dcast(lrpair_real , formula = ligand ~ receptor , fill = 0 , value.var = " lr_co_exp_num" )
658+ rownames(lrpair_mat ) <- lrpair_mat $ ligand
659+ lrpair_mat <- lrpair_mat [, - 1 ]
660+ heat_color <- grDevices :: colorRampPalette(c(color_low , color_high ))(max(as.matrix(lrpair_mat ))- 1 )
661+ heat_color <- c(" white" , heat_color )
662+ pheatmap :: pheatmap(lrpair_mat , cluster_cols = F , cluster_rows = F , border_color = border_color , color = heat_color , main = " Number of spatial LRIs" )
663+ }
646664}
647665
648666# ' @title Plot LR pair
0 commit comments