Skip to content

Commit b3c956d

Browse files
committed
Allow use of scattermore/scattermost in plotPairs
1 parent 1e8a5db commit b3c956d

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ Suggests:
5555
knitr,
5656
Biostrings,
5757
pwalign,
58-
plotly
58+
plotly,
59+
scattermore
5960
SystemRequirements: GNU make
6061
biocViews: GeneticVariability, GenomicVariation, Preprocessing
6162
License: MIT + file LICENSE

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# mutscan 0.3.4
2+
3+
* Allow use of scattermore/scattermost in plotPairs
4+
15
# mutscan 0.3.3
26

37
* Bugfix in mergeReadPairPartial for situation where specified minMergedLength/maxMergedLength is larger than the total length of the two merged sequences

R/plotPairs.R

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
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
@@ -168,11 +173,61 @@ plotPairs <- function(se, selAssay = "counts", doLog = TRUE, pseudocount = 1,
168173
}
169174
}
170175

176+
## Define function to create scattermore plot (for use with ggpairs)
177+
if (addIdentityLine) {
178+
plotscattermore <- function(data, mapping, ...) {
179+
ggplot2::ggplot(data = data, mapping = mapping) +
180+
ggplot2::geom_abline(slope = 1, intercept = 0,
181+
linetype = "dashed", color = "grey") +
182+
scattermore::geom_scattermore(alpha = pointAlpha,
183+
pointsize = pointSize) +
184+
ggtheme
185+
}
186+
} else {
187+
plotscattermore <- function(data, mapping, ...) {
188+
ggplot2::ggplot(data = data, mapping = mapping) +
189+
scattermore::geom_scattermore(alpha = pointAlpha,
190+
pointsize = pointSize) +
191+
ggtheme
192+
}
193+
}
194+
195+
## Define function to create scattermost plot (for use with ggpairs)
196+
if (addIdentityLine) {
197+
plotscattermost <- function(data, mapping, ...) {
198+
## Get data
199+
xData <- GGally::eval_data_col(data, mapping$x)
200+
yData <- GGally::eval_data_col(data, mapping$y)
201+
202+
ggplot2::ggplot(data = data, mapping = mapping) +
203+
ggplot2::geom_abline(slope = 1, intercept = 0,
204+
linetype = "dashed", color = "grey") +
205+
scattermore::geom_scattermost(xy = cbind(xData, yData),
206+
pointsize = pointSize) +
207+
ggtheme
208+
}
209+
} else {
210+
plotscattermost <- function(data, mapping, ...) {
211+
## Get data
212+
xData <- GGally::eval_data_col(data, mapping$x)
213+
yData <- GGally::eval_data_col(data, mapping$y)
214+
215+
ggplot2::ggplot(data = data, mapping = mapping) +
216+
scattermore::geom_scattermost(xy = cbind(xData, yData),
217+
pointsize = pointSize) +
218+
ggtheme
219+
}
220+
}
221+
171222
## Define the function to use for the plots
172223
if (pointsType == "smoothscatter") {
173224
lower <- list(continuous = smoothscat)
174225
} else if (pointsType == "points") {
175226
lower <- list(continuous = plotpoints)
227+
} else if (pointsType == "scattermore") {
228+
lower <- list(continuous = plotscattermore)
229+
} else if (pointsType == "scattermost") {
230+
lower <- list(continuous = plotscattermost)
176231
}
177232

178233
## ----------------------------------------------------------------------- ##

man/plotPairs.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)