@@ -570,12 +570,7 @@ plotBeeswarm <-
570570 y = " " ,
571571 size = " %" ) +
572572 ggplot2 :: scale_x_discrete(labels = " mean % across\n all samples" ) +
573- {
574- if (isFALSE(x = .order.ids )){
575- ggplot2 :: scale_y_discrete(limits = rev )
576- }
577-
578- } +
573+ ggplot2 :: scale_y_discrete(limits = rev ) +
579574 ggplot2 :: scale_size_continuous(range = log2(x = x $ cell.perc + 1 ) | >
580575 range() | >
581576 I()) +
@@ -736,12 +731,7 @@ plotBeeswarm <-
736731 scales = .facet.scales )
737732 }
738733 } +
739- {
740- if (isFALSE(x = .order.ids )){
741- ggplot2 :: scale_y_discrete(limits = rev )
742- }
743-
744- } +
734+ ggplot2 :: scale_y_discrete(limits = rev ) +
745735 ggplot2 :: geom_point(position = ggplot2 :: position_jitter(width = 0 ,
746736 height = 0.25 ),
747737 size = I(x = .point.size )) +
@@ -898,7 +888,7 @@ plot2Markers <-
898888
899889 dat.df <-
900890 (.lm.obj $ lm [if (! is.null(x = .id )) .id else 1 : nrow(x = .lm.obj $ lm ),
901- colnames(x = .lm.obj $ lm ) %in% c(.x.feature ,.y.feature )]/ 50 ) | >
891+ colnames(x = .lm.obj $ lm ) %in% c(.x.feature ,.y.feature )]) | >
902892 as.data.frame()
903893
904894 }
@@ -936,7 +926,7 @@ plot2Markers <-
936926
937927 p <-
938928 p +
939- ggplot2 :: stat_density_2d(data = as.data.frame(x = .lm.obj $ lm / ( if ( .lm.obj $ assay.type == " RNA " ) 1 else 50 ) ),
929+ ggplot2 :: stat_density_2d(data = as.data.frame(x = .lm.obj $ lm ),
940930 mapping = ggplot2 :: aes(fill = ggplot2 :: after_stat(x = log2(x = level ))),
941931 geom = " polygon" ,
942932 bins = .density.bins ) +
@@ -1197,12 +1187,7 @@ plotTradStats <-
11971187 y = " " ,
11981188 size = " %" ) +
11991189 ggplot2 :: scale_x_discrete(labels = " mean % across\n all samples" ) +
1200- {
1201- if (isFALSE(x = .order.ids )){
1202- ggplot2 :: scale_y_discrete(limits = rev )
1203- }
1204-
1205- } +
1190+ ggplot2 :: scale_y_discrete(limits = rev ) +
12061191 ggplot2 :: scale_size_continuous(range = log2(x = x $ cell.perc + 1 ) | >
12071192 range()) +
12081193 ggplot2 :: geom_point() +
@@ -1296,23 +1281,13 @@ plotTradStats <-
12961281 ggplot2 :: scale_fill_gradient2(low = unname(obj = Color.Palette [1 ,1 ]),
12971282 mid = unname(obj = Color.Palette [1 ,6 ]),
12981283 high = unname(obj = Color.Palette [1 ,2 ]),
1299- midpoint = 0 # ,
1300- # labels = ~ ifelse(test = .x >= 0,
1301- # yes = round(x = 2^.x,
1302- # digits = 1),
1303- # no = -round(x = 1 / 2^.x,
1304- # digits = 1))
1284+ midpoint = 0
13051285 ) +
13061286 ggplot2 :: scale_size_continuous(labels = ~ formatC(x = 10 ^ (- (.x )),
13071287 format = " g" ,
13081288 digits = 1 ),
13091289 range = I(x = c(3 ,6 ))) +
1310- {
1311- if (isFALSE(x = .order.ids )){
1312- ggplot2 :: scale_y_discrete(limits = rev )
1313- }
1314-
1315- } +
1290+ ggplot2 :: scale_y_discrete(limits = rev ) +
13161291 ggplot2 :: geom_point(shape = 21 ,
13171292 mapping = ggplot2 :: aes(size = - log10(x = adj.p )),
13181293 color = " black" ,
@@ -1360,10 +1335,12 @@ plotTradStats <-
13601335# '
13611336# ' @param .lm.obj A tinydenseR object processed through \code{get.map()}.
13621337# ' @param .x.split Character specifying metadata column for x-axis grouping. Defaults to first
1363- # ' column (often "Condition").
1338+ # ' column.
1339+ # ' @param .x.split.subset Optional character vector to subset \code{.x.split} categories. Default NULL.
13641340# ' @param .pop Character vector of population names to plot. If NULL, plots all populations from
13651341# ' \code{.pop.from}.
13661342# ' @param .pop.from Character: "clustering" (default) or "celltyping" - which grouping to plot.
1343+ # ' @param .order.pop Logical whether to order populations based on dendrogram order (default FALSE).
13671344# ' @param .line.by Character metadata column for connecting paired samples with lines (e.g.,
13681345# ' "Subject" for longitudinal data). Default NULL (no lines).
13691346# ' @param .dodge.by Character metadata column for coloring/dodging points. Default NULL (all black).
@@ -1373,6 +1350,7 @@ plotTradStats <-
13731350# ' \code{Color.Palette[1,1:5]}).
13741351# ' @param .seed Integer random seed for x-axis jitter (default 123).
13751352# ' @param .orientation Character: "wide" (default, all populations in one row) or "square" (facet grid).
1353+ # ' @param .log2.y Logical whether to log2-transform y-axis percentages (default FALSE).
13761354# '
13771355# ' @return A \code{ggplot} object showing cell percentages with optional paired connections.
13781356# '
@@ -1413,15 +1391,18 @@ plotTradPerc <-
14131391 function (
14141392 .lm.obj ,
14151393 .x.split = colnames(x = .lm.obj $ metadata )[1 ],
1394+ .x.split.subset = NULL ,
14161395 .pop = NULL ,
14171396 .pop.from = " clustering" ,
1397+ .order.pop = FALSE ,
14181398 .line.by = NULL ,
14191399 .dodge.by = NULL ,
14201400 .x.space.scaler = 0.25 ,
14211401 .height = 1.5 ,
14221402 .cat.feature.color = Color.Palette [1 ,1 : 5 ],
14231403 .seed = 123 ,
1424- .orientation = " wide"
1404+ .orientation = " wide" ,
1405+ .log2.y = FALSE
14251406 ){
14261407
14271408 dodge <- value <- name <- color <- group <- x <- y <- NULL
@@ -1436,6 +1417,14 @@ plotTradPerc <-
14361417 collapse = " , " )))
14371418 }
14381419
1420+ if (! is.null(x = .x.split.subset )){
1421+ if (! all(.x.split.subset %in% .lm.obj $ metadata [[.x.split ]])){
1422+ stop(paste0(" .x.split.subset must within the following: " ,
1423+ paste(x = unique(x = .lm.obj $ metadata [[.x.split ]]),
1424+ collapse = " , " )))
1425+ }
1426+ }
1427+
14391428 if (! is.null(x = .dodge.by )){
14401429 if (length(x = .dodge.by ) != 1 ){
14411430 stop(" .dodge.by must be length 1" )
@@ -1506,6 +1495,23 @@ plotTradPerc <-
15061495
15071496 }
15081497
1498+ if (! is.null(x = .x.split.subset )){
1499+
1500+ dat.df <-
1501+ droplevels(x = dat.df [dat.df $ x %in% .x.split.subset ,])
1502+
1503+ }
1504+
1505+ if (isTRUE(x = .order.pop )){
1506+
1507+ dat.df $ name <-
1508+ as.character(x = dat.df $ name ) | >
1509+ factor (levels = .lm.obj $ graph [[.pop.from ]]$ pheatmap $ tree_row $ labels [
1510+ .lm.obj $ graph [[.pop.from ]]$ pheatmap $ tree_row $ order
1511+ ])
1512+
1513+ }
1514+
15091515 p <-
15101516 ggplot2 :: ggplot(data = dat.df ,
15111517 mapping = ggplot2 :: aes(x = x ,
@@ -1579,6 +1585,12 @@ plotTradPerc <-
15791585 seed = .seed ))
15801586 }
15811587
1588+ if (isTRUE(x = .log2.y )){
1589+ p <-
1590+ p +
1591+ ggplot2 :: scale_y_continuous(transform = " log2" )
1592+ }
1593+
15821594 p
15831595
15841596 }
0 commit comments