Skip to content

Commit c1fc918

Browse files
authored
Merge pull request #34 from fmicompbio/update-plotpairs
ADd option to include identity line in pairs plots; select points to …
2 parents 88bce82 + 84ba630 commit c1fc918

File tree

10 files changed

+284
-187
lines changed

10 files changed

+284
-187
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: mutscan
22
Title: Preprocessing and Analysis of Deep Mutational Scanning Data
3-
Version: 0.2.30
3+
Version: 0.2.31
44
Authors@R:
55
c(person(given = "Charlotte",
66
family = "Soneson",

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ importFrom(ggplot2,coord_cartesian)
6868
importFrom(ggplot2,element_blank)
6969
importFrom(ggplot2,element_text)
7070
importFrom(ggplot2,facet_wrap)
71+
importFrom(ggplot2,geom_abline)
7172
importFrom(ggplot2,geom_bar)
7273
importFrom(ggplot2,geom_density)
7374
importFrom(ggplot2,geom_histogram)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# mutscan 0.2.31
2+
3+
* Add option to include identity line in pairs plots
4+
* Select points to label in result plots based on nominal p-value
5+
* Add option to manually set the correlation range for coloring pairs plots
6+
17
# mutscan 0.2.30
28

39
* Swap to MIT license

R/plotPairs.R

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@
3232
#' opacity of points in the plot.
3333
#' @param colorByCorrelation Logical scalar, indicating whether the correlation
3434
#' panels should be colored according to the correlation value.
35+
#' @param corrColorRange Numeric vector of length 2, providing the lower and
36+
#' upper limits of the color scale when coloring by correlation. Both
37+
#' values should be positive; the same range is used for negative
38+
#' correlations. If \code{NULL} (the default), the range is inferred from
39+
#' the data.
40+
#' @param addIdentityLine Logical scalar, indicating whether the identity line
41+
#' should be added (only used if \code{pointsType = "points"}).
3542
#'
3643
#' @importFrom GGally eval_data_col ggpairs wrap
3744
#' @importFrom ggplot2 ggplot annotate theme_void ylim stat_density2d
3845
#' scale_fill_continuous geom_point theme_bw theme element_blank aes
39-
#' geom_histogram scale_x_continuous scale_y_continuous
46+
#' geom_histogram scale_x_continuous scale_y_continuous geom_abline
4047
#' @importFrom stats cor
4148
#' @importFrom SummarizedExperiment assayNames assay
4249
#' @importFrom grDevices hcl.colors rgb colorRamp
@@ -46,7 +53,8 @@ plotPairs <- function(se, selAssay = "counts", doLog = TRUE, pseudocount = 1,
4653
corMethod = "pearson", histBreaks = 40,
4754
pointsType = "points", corSizeMult = 5,
4855
corSizeAdd = 2, pointSize = 0.1, pointAlpha = 0.3,
49-
colorByCorrelation = TRUE) {
56+
colorByCorrelation = TRUE, corrColorRange = NULL,
57+
addIdentityLine = FALSE) {
5058

5159
.assertVector(x = se, type = "SummarizedExperiment")
5260
.assertScalar(x = selAssay, type = "character",
@@ -63,6 +71,12 @@ plotPairs <- function(se, selAssay = "counts", doLog = TRUE, pseudocount = 1,
6371
.assertScalar(x = pointSize, type = "numeric", rngExcl = c(0, Inf))
6472
.assertScalar(x = pointAlpha, type = "numeric", rngExcl = c(0, Inf))
6573
.assertScalar(x = colorByCorrelation, type = "logical")
74+
.assertVector(x = corrColorRange, type = "numeric", rngIncl = c(0, 1),
75+
len = 2, allowNULL = TRUE)
76+
if (!is.null(corrColorRange)) {
77+
stopifnot(corrColorRange[2] >= corrColorRange[1])
78+
}
79+
.assertScalar(x = addIdentityLine, type = "logical")
6680

6781
## ----------------------------------------------------------------------- ##
6882
## Define shared theme elements
@@ -131,12 +145,22 @@ plotPairs <- function(se, selAssay = "counts", doLog = TRUE, pseudocount = 1,
131145
}
132146

133147
## Define function to create scatter plot (for use with ggpairs)
134-
plotpoints <- function(data, mapping, ...) {
135-
ggplot2::ggplot(data = data, mapping = mapping) +
136-
ggplot2::geom_point(alpha = pointAlpha, size = pointSize) +
137-
ggtheme
148+
if (addIdentityLine) {
149+
plotpoints <- function(data, mapping, ...) {
150+
ggplot2::ggplot(data = data, mapping = mapping) +
151+
ggplot2::geom_abline(slope = 1, intercept = 0,
152+
linetype = "dashed", color = "grey") +
153+
ggplot2::geom_point(alpha = pointAlpha, size = pointSize) +
154+
ggtheme
155+
}
156+
} else {
157+
plotpoints <- function(data, mapping, ...) {
158+
ggplot2::ggplot(data = data, mapping = mapping) +
159+
ggplot2::geom_point(alpha = pointAlpha, size = pointSize) +
160+
ggtheme
161+
}
138162
}
139-
163+
140164
## Define the function to use for the plots
141165
if (pointsType == "smoothscatter") {
142166
lower <- list(continuous = smoothscat)
@@ -176,7 +200,11 @@ plotPairs <- function(se, selAssay = "counts", doLog = TRUE, pseudocount = 1,
176200

177201
## Calculate correlations and get range
178202
allCors <- stats::cor(mat, method = corMethod)
179-
corRange <- range(abs(allCors[upper.tri(allCors)]))
203+
if (!is.null(corrColorRange)) {
204+
corRange <- corrColorRange
205+
} else {
206+
corRange <- range(abs(allCors[upper.tri(allCors)]))
207+
}
180208
if (length(unique(corRange)) == 1) {
181209
## Having a range with width 0 leads to problems in the rescaling of the correlations
182210
corRange <- c(0, 1)

0 commit comments

Comments
 (0)