2727# ' @param backgroundColors Color palette to be used for the background coloring.
2828# ' Can be either a function or an array specifying
2929# ' colors.
30+ # ' @param backgroundSize The size of the background. Will be multiplied by the
31+ # ' size of the nodes.
32+ # ' @param equalBackgroundSize If you want the background sizes to be the same size.
3033# ' @param backgroundLim Only used when backgroundValues are numerical.
3134# ' Defaults to min and max of the backgroundValues.
3235# ' @param title Title of the plot
@@ -69,6 +72,8 @@ PlotFlowSOM <- function(fsom,
6972 equalNodeSize = FALSE ,
7073 backgroundValues = NULL ,
7174 backgroundColors = NULL ,
75+ backgroundSize = 1.5 ,
76+ equalBackgroundSize = FALSE ,
7277 backgroundLim = NULL ,
7378 title = NULL )
7479{
@@ -96,16 +101,16 @@ PlotFlowSOM <- function(fsom,
96101 warning(paste0(" In the new FlowSOM version \" backgroundColors\" " ,
97102 " is used instead of \" backgroundColor\" " ))
98103 }
99-
104+
100105
101106 # ---- Layout----
102107 layout <- ParseLayout(fsom , view )
103108 if (is.matrix(view ) || is.data.frame(view )) view <- " matrix"
104109
105110 # ---- Nodesize----
106111 autoNodeSize <- AutoMaxNodeSize(layout = layout ,
107- overlap = ifelse(view %in% c(" grid" ),
108- - 0.3 , 1 ))
112+ overlap = ifelse(view %in% c(" grid" ),
113+ - 0.3 , 1 ))
109114 maxNodeSize <- autoNodeSize * maxNodeSize
110115
111116 if (equalNodeSize ){
@@ -117,10 +122,15 @@ PlotFlowSOM <- function(fsom,
117122 if (any(isEmpty )) {scaledNodeSize [isEmpty ] <- min(maxNodeSize , 0.05 )}
118123
119124 # ----ggplot----
125+ if (equalBackgroundSize ){
126+ backgroundSize <- rep(maxNodeSize , nNodes ) * backgroundSize
127+ } else {
128+ backgroundSize <- ParseNodeSize(nodeSizes , maxNodeSize , refNodeSize ) * backgroundSize
129+ }
120130 plot_df <- data.frame (x = layout $ x ,
121131 y = layout $ y ,
122132 size = scaledNodeSize ,
123- bg_size = scaledNodeSize * 1.5 )
133+ bg_size = backgroundSize )
124134
125135 p <- ggplot2 :: ggplot(plot_df )
126136
@@ -226,7 +236,7 @@ PlotStars <- function(fsom,
226236
227237 if (length(names(list (... ))) > 0 && " backgroundColor" %in% names(list (... ))){
228238 warning(paste0(" \" backgroundColor\" is deprecated, " ,
229- " please use \" backgroundColors\" instead." ))
239+ " please use \" backgroundColors\" instead." ))
230240 }
231241
232242 channels <- GetChannels(fsom , markers )
@@ -485,7 +495,7 @@ PlotNumbers <- function(fsom,
485495 ... )
486496 return (p )
487497}
488-
498+
489499# ' PlotMarker
490500# '
491501# ' Plot comparison with other clustering
@@ -563,7 +573,7 @@ PlotMarker <- function(fsom,
563573
564574 # Get column names
565575 channels <- GetChannels(fsom , marker )
566-
576+
567577 # Compute limits based on all reference markers
568578 ref_channels <- GetChannels(fsom , refMarkers )
569579 if (is.null(lim )) lim <- c(min(mfis [, ref_channels ]),
@@ -583,7 +593,7 @@ PlotMarker <- function(fsom,
583593 if (is.na(title [channelI ])) title [channelI ] <- " "
584594 p <- p + ggplot2 :: ggtitle(title [channelI ])
585595 })
586-
596+
587597 p <- ggpubr :: ggarrange(plotlist = plotList , common.legend = TRUE ,
588598 legend = " right" )
589599
@@ -796,11 +806,11 @@ PlotDimRed <- function(fsom,
796806 dimred_plot <- dimred_plot %> % tidyr :: pivot_longer(3 : ncol(dimred_plot ),
797807 names_to = " markers" )
798808 if (requireNamespace(" scattermore" , quietly = TRUE )) {
799- p <- ggplot2 :: ggplot(dimred_plot ) +
800- scattermore :: geom_scattermore(ggplot2 :: aes(x = .data $ dimred_1 ,
801- y = .data $ dimred_2 ,
802- col = .data $ value ),
803- pointsize = 1 )
809+ p <- ggplot2 :: ggplot(dimred_plot ) +
810+ scattermore :: geom_scattermore(ggplot2 :: aes(x = .data $ dimred_1 ,
811+ y = .data $ dimred_2 ,
812+ col = .data $ value ),
813+ pointsize = 1 )
804814 } else {
805815 message(" For faster plotting with more datapoints, please install \" scattermore\" " )
806816 p <- ggplot2 :: ggplot(dimred_plot ) +
@@ -1007,7 +1017,7 @@ PlotManualBars <- function(fsom, fcs = NULL,
10071017 dplyr :: mutate(" MC" = factor (.data $ MC , levels = levels(fsom $ metaclustering ))) %> %
10081018 dplyr :: mutate(" C" = factor (.data $ C , levels = seq_len(NClusters(fsom )))) %> %
10091019 dplyr :: mutate(" Manual" = factor (.data $ Manual , levels = manualOrder ))
1010-
1020+
10111021 p3 <- ggplot2 :: ggplot(data = df_s ,
10121022 ggplot2 :: aes(fill = .data $ Manual ,
10131023 y = .data $ Freq ,
@@ -1946,7 +1956,7 @@ AddStarsPies <- function(p, arcs, colorPalette, showLegend = TRUE){
19461956 start = .data $ start ,
19471957 end = .data $ end ,
19481958 fill = .data $ Markers ),
1949- size = 0.2 )
1959+ linewidth = 0.2 )
19501960
19511961
19521962 return (p )
@@ -2038,7 +2048,7 @@ AddNodes <- function(p,
20382048 y0 = .data $ y ,
20392049 r = .data $ size ),
20402050 fill = fillColor ,
2041- size = 0.2 ,
2051+ linewidth = 0.2 ,
20422052 ... )
20432053 } else {
20442054
@@ -2055,7 +2065,7 @@ AddNodes <- function(p,
20552065 y0 = .data $ y ,
20562066 r = .data $ size ,
20572067 fill = values ),
2058- size = 0.2 ,
2068+ linewidth = 0.2 ,
20592069 ... )
20602070 }
20612071 return (p )
@@ -2510,12 +2520,12 @@ FlowSOMmary <- function(fsom, plotFile = "FlowSOMmary.pdf"){
25102520 if (metaclustersPresent ) {
25112521 datatable1 [, " Total number of metaclusters" ] <- nMetaclusters
25122522 }
2513-
2523+
25142524 markersInFlowSOM <- split(fsom $ prettyColnames [fsom $ map $ colsUsed ],
25152525 rep(seq_len(ceiling(length(fsom $ prettyColnames [
25162526 fsom $ map $ colsUsed ])/ 5 )),
2517- each = 5 )[seq_len(length(fsom $ prettyColnames [
2518- fsom $ map $ colsUsed ]))]) %> %
2527+ each = 5 )[seq_len(length(fsom $ prettyColnames [
2528+ fsom $ map $ colsUsed ]))]) %> %
25192529 sapply(paste , collapse = " , " ) %> %
25202530 paste(collapse = " ,\n " )
25212531
@@ -2744,7 +2754,7 @@ AddAnnotation <- function(p,
27442754 nudge_x = 0.5 , ... )
27452755 message(" Please install \" ggrepel\" for more clear annotation." )
27462756 }
2747-
2757+
27482758 if (listOrGGplot ){
27492759 p <- ggpubr :: ggarrange(p , ggpubr :: ggarrange(l1 , l2 , ncol = 1 ), NULL ,
27502760 ncol = 3 , widths = c(3 , 1 , 0.3 ), legend = " none" )
@@ -2810,4 +2820,4 @@ PlotOutliers <- function(fsom, outlierReport){
28102820 })
28112821 p <- suppressMessages(ggpubr :: ggarrange(plotlist = plotList ))
28122822 return (p )
2813- }
2823+ }
0 commit comments