@@ -83,7 +83,9 @@ setGeneric( "plotReverseCumulatives",
83
83
.plotReverseCumulatives <-
84
84
function ( object , values = c(" raw" , " normalized" )
85
85
, fitInRange = c(10 , 1000 )
86
- , group = NULL ) {
86
+ , group = NULL
87
+ , xlim = c(1 , 1e5 )
88
+ , ylim = c(1 , 1e6 )) {
87
89
if (is.null(object @ metadata $ colData ))
88
90
stop(" Expects a List-like object with a colData DataFrame in its metadata slot." )
89
91
@@ -101,11 +103,6 @@ setGeneric( "plotReverseCumulatives",
101
103
group <- " group"
102
104
}
103
105
104
- # no need for colors if a multi-facet plot and many colors
105
- if (is.null(object @ metadata $ colData $ Colors )) {
106
- object @ metadata $ colData $ Colors <- scales :: hue_pal()(length(object ))
107
- }
108
-
109
106
toCumSums <- function (exprValues , sampleName ) {
110
107
# See benchmarks/sorted-abundance-benchmark.Rmd in the CAGEr's Git repository
111
108
exprValues <- exprValues [exprValues != 0 ]
@@ -123,14 +120,9 @@ setGeneric( "plotReverseCumulatives",
123
120
# Enforce original sample order
124
121
DF $ plotOrder <- DF $ sampleLabels | > ordered(unique(DF $ sampleLabels ))
125
122
126
- p <- as.data.frame(DF ) | >
123
+ intermediate_df <- as.data.frame(DF ) | >
127
124
merge( object @ metadata $ colData [,c(' sampleLabels' , group )] | > as.data.frame()
128
- , by = " sampleLabels" ) | > ggplot() +
129
- aes(.data $ x , .data $ y , col = .data $ plotOrder ) +
130
- geom_step() +
131
- scale_x_log10() + scale_y_log10() +
132
- xlab(xlab ) + ylab(ylab ) +
133
- ggtitle(" Reverse-cumulative plot" )
125
+ , by = " sampleLabels" )
134
126
135
127
if (! is.null(fitInRange )) {
136
128
fit.coefs.m <- sapply(object , val.range = fitInRange , \(x , val.range )
@@ -139,20 +131,32 @@ setGeneric( "plotReverseCumulatives",
139
131
reference.slope <- min(median(fit.slopes ), - 1.05 )
140
132
reference.library.size <- 10 ^ floor(log10(median(sapply(object , sum ))))
141
133
reference.intercept <- log10(reference.library.size / VGAM :: zeta(- 1 * reference.slope )) # intercept on log10 scale used for plotting with abline
142
- p <- p +
143
- geom_abline(intercept = reference.intercept , slope = reference.slope , color = " grey" , linetype = " longdash" ) +
144
- geom_vline(xintercept = fitInRange , color = " darkgrey" , linetype = " dotted" ) +
145
- scale_color_manual(
146
- values = object @ metadata $ colData $ Colors ,
147
- labels = paste0(" (" , formatC(- fit.slopes , format = " f" , digits = 2 ), " ) " , names(fit.slopes ))) +
148
- labs(subtitle = paste0(" Ref. distribution alpha = " , sprintf(" %.2f" , - reference.slope ), " , T = " , reference.library.size , " ." )) +
149
- guides(col = guide_legend(title = " (alpha) sample names" ))
150
- } else {
151
- p <- p +
152
- scale_color_manual(values = object @ metadata $ colData $ Colors )
153
- guides(col = guide_legend(title = " Sample names" ))
154
134
}
155
- p + facet_wrap(group )
135
+
136
+ plot_out <- ggplot2 :: ggplot(intermediate_df ) +
137
+ ggplot2 :: aes(x = x , y = y ) +
138
+ ggplot2 :: geom_line() +
139
+ ggplot2 :: facet_wrap(. ~ sampleLabels ) +
140
+ xlim(xlim [1 ], xlim [2 ]) +
141
+ ylim(ylim [1 ], ylim [2 ]) +
142
+ scale_x_continuous(trans = ' log10' ) +
143
+ scale_y_continuous(trans = ' log10' ) +
144
+ labs(title = " Reference distribution:" ,
145
+ subtitle = paste0(" alpha= " , sprintf(" %.2f" , - 1 * reference.slope ), " T= " , reference.library.size ),
146
+ x = xlab , y = ylab ) +
147
+ ggplot2 :: geom_text(data = intermediate_df ,
148
+ mapping = aes(
149
+ x = 10 , y = 10 ,
150
+ label = paste0(" alpha= " , formatC(- 1 * fit.slopes [sampleLabels ], format = " f" , digits = 2 )))) +
151
+ ggplot2 :: geom_vline(xintercept = fitInRange , linetype = " dotted" ) +
152
+ ggplot2 :: geom_abline(slope = reference.slope , intercept = reference.intercept ,
153
+ linetype = " longdash" , colour = " #7F7F7F7F" )
154
+
155
+ if (TOPLOT ){
156
+ print(plot_out )
157
+ }
158
+
159
+ return (list (plot_out , reference.slope , reference.library.size , reference.intercept ))
156
160
}
157
161
158
162
# ' @rdname plotReverseCumulatives
0 commit comments