2323# ' to calculate.
2424# ' @param histBreaks Numeric scalar, the number of breaks in the histograms
2525# ' to put in the diagonal panels.
26- # ' @param pointsType Either "points" or "smoothscatter", determining the
27- # ' type of plots that will be made.
26+ # ' @param pointsType Either "points", "smoothscatter", "scattermore" or
27+ # ' "scattermost" (the latter two require the "scattermore" package to be
28+ # ' installed), determining the type of plots that will be made.
2829# ' @param corSizeMult,corSizeAdd Numeric scalars determining how the
2930# ' absolute correlation value is transformed into a font size. The
3031# ' transformation is corSizeMult * abs(corr) + corSizeAdd.
@@ -71,7 +72,8 @@ plotPairs <- function(se, selAssay = "counts", doLog = TRUE, pseudocount = 1,
7172 validValues = c(" pearson" , " spearman" ))
7273 .assertScalar(x = histBreaks , type = " numeric" , rngExcl = c(0 , Inf ))
7374 .assertScalar(x = pointsType , type = " character" ,
74- validValues = c(" smoothscatter" , " points" ))
75+ validValues = c(" smoothscatter" , " points" , " scattermore" ,
76+ " scattermost" ))
7577 .assertScalar(x = corSizeMult , type = " numeric" , rngExcl = c(0 , Inf ))
7678 .assertScalar(x = corSizeAdd , type = " numeric" , rngIncl = c(0 , Inf ))
7779 .assertScalar(x = pointSize , type = " numeric" , rngExcl = c(0 , Inf ))
@@ -83,6 +85,9 @@ plotPairs <- function(se, selAssay = "counts", doLog = TRUE, pseudocount = 1,
8385 stopifnot(corrColorRange [2 ] > = corrColorRange [1 ])
8486 }
8587 .assertScalar(x = addIdentityLine , type = " logical" )
88+ if (pointsType %in% c(" scattermore" , " scattermost" )) {
89+ .assertPackagesAvailable(" scattermore" )
90+ }
8691
8792 # # ----------------------------------------------------------------------- ##
8893 # # Define shared theme elements
@@ -140,31 +145,80 @@ plotPairs <- function(se, selAssay = "counts", doLog = TRUE, pseudocount = 1,
140145 # # ----------------------------------------------------------------------- ##
141146 # # Scatter plots
142147 # # ----------------------------------------------------------------------- ##
143- # # Define function to create smoothscatter-like plot (for use with ggpairs)
144- smoothscat <- function (data , mapping , ... ) {
145- ggplot2 :: ggplot(data = data , mapping = mapping ) +
146- ggplot2 :: stat_density2d(ggplot2 :: aes(fill = ggplot2 :: after_stat(.data $ density )^ 0.25 ), geom = " tile" ,
147- contour = FALSE , n = 200 ) +
148- ggplot2 :: scale_fill_continuous(low = " white" , high = " darkgreen" ) +
149- ggtheme +
150- ggplot2 :: scale_x_continuous(expand = c(0 , 0 )) +
151- ggplot2 :: scale_y_continuous(expand = c(0 , 0 ))
152- }
153-
154- # # Define function to create scatter plot (for use with ggpairs)
155- if (addIdentityLine ) {
156- plotpoints <- function (data , mapping , ... ) {
148+ if (pointsType == " smoothscatter" ) {
149+ # # Define function to create smoothscatter-like plot (for use with ggpairs)
150+ smoothscat <- function (data , mapping , ... ) {
157151 ggplot2 :: ggplot(data = data , mapping = mapping ) +
158- ggplot2 :: geom_abline(slope = 1 , intercept = 0 ,
159- linetype = " dashed" , color = " grey" ) +
160- ggplot2 :: geom_point(alpha = pointAlpha , size = pointSize ) +
161- ggtheme
152+ ggplot2 :: stat_density2d(
153+ ggplot2 :: aes(fill = ggplot2 :: after_stat(.data $ density )^ 0.25 ), geom = " tile" ,
154+ contour = FALSE , n = 200 ) +
155+ ggplot2 :: scale_fill_continuous(low = " white" , high = " darkgreen" ) +
156+ ggtheme +
157+ ggplot2 :: scale_x_continuous(expand = c(0 , 0 )) +
158+ ggplot2 :: scale_y_continuous(expand = c(0 , 0 ))
162159 }
163- } else {
164- plotpoints <- function (data , mapping , ... ) {
165- ggplot2 :: ggplot(data = data , mapping = mapping ) +
166- ggplot2 :: geom_point(alpha = pointAlpha , size = pointSize ) +
167- ggtheme
160+ } else if (pointsType == " points" ) {
161+ # # Define function to create scatter plot (for use with ggpairs)
162+ if (addIdentityLine ) {
163+ plotpoints <- function (data , mapping , ... ) {
164+ ggplot2 :: ggplot(data = data , mapping = mapping ) +
165+ ggplot2 :: geom_abline(slope = 1 , intercept = 0 ,
166+ linetype = " dashed" , color = " grey" ) +
167+ ggplot2 :: geom_point(alpha = pointAlpha , size = pointSize ) +
168+ ggtheme
169+ }
170+ } else {
171+ plotpoints <- function (data , mapping , ... ) {
172+ ggplot2 :: ggplot(data = data , mapping = mapping ) +
173+ ggplot2 :: geom_point(alpha = pointAlpha , size = pointSize ) +
174+ ggtheme
175+ }
176+ }
177+ } else if (pointsType == " scattermore" ) {
178+ # # Define function to create scattermore plot (for use with ggpairs)
179+ if (addIdentityLine ) {
180+ plotscattermore <- function (data , mapping , ... ) {
181+ ggplot2 :: ggplot(data = data , mapping = mapping ) +
182+ ggplot2 :: geom_abline(slope = 1 , intercept = 0 ,
183+ linetype = " dashed" , color = " grey" ) +
184+ scattermore :: geom_scattermore(alpha = pointAlpha ,
185+ pointsize = pointSize ) +
186+ ggtheme
187+ }
188+ } else {
189+ plotscattermore <- function (data , mapping , ... ) {
190+ ggplot2 :: ggplot(data = data , mapping = mapping ) +
191+ scattermore :: geom_scattermore(alpha = pointAlpha ,
192+ pointsize = pointSize ) +
193+ ggtheme
194+ }
195+ }
196+ } else if (pointsType == " scattermost" ) {
197+ # # Define function to create scattermost plot (for use with ggpairs)
198+ if (addIdentityLine ) {
199+ plotscattermost <- function (data , mapping , ... ) {
200+ # # Get data
201+ xData <- GGally :: eval_data_col(data , mapping $ x )
202+ yData <- GGally :: eval_data_col(data , mapping $ y )
203+
204+ ggplot2 :: ggplot(data = data , mapping = mapping ) +
205+ ggplot2 :: geom_abline(slope = 1 , intercept = 0 ,
206+ linetype = " dashed" , color = " grey" ) +
207+ scattermore :: geom_scattermost(xy = cbind(xData , yData ),
208+ pointsize = pointSize ) +
209+ ggtheme
210+ }
211+ } else {
212+ plotscattermost <- function (data , mapping , ... ) {
213+ # # Get data
214+ xData <- GGally :: eval_data_col(data , mapping $ x )
215+ yData <- GGally :: eval_data_col(data , mapping $ y )
216+
217+ ggplot2 :: ggplot(data = data , mapping = mapping ) +
218+ scattermore :: geom_scattermost(xy = cbind(xData , yData ),
219+ pointsize = pointSize ) +
220+ ggtheme
221+ }
168222 }
169223 }
170224
@@ -173,6 +227,10 @@ plotPairs <- function(se, selAssay = "counts", doLog = TRUE, pseudocount = 1,
173227 lower <- list (continuous = smoothscat )
174228 } else if (pointsType == " points" ) {
175229 lower <- list (continuous = plotpoints )
230+ } else if (pointsType == " scattermore" ) {
231+ lower <- list (continuous = plotscattermore )
232+ } else if (pointsType == " scattermost" ) {
233+ lower <- list (continuous = plotscattermost )
176234 }
177235
178236 # # ----------------------------------------------------------------------- ##
0 commit comments