Skip to content

Commit

Permalink
add min.segment.length
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinblighe committed Jul 23, 2021
1 parent e6ef6db commit 4aff21e
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 147 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: EnhancedVolcano
Type: Package
Title: Publication-ready volcano plots with enhanced colouring and labeling
Version: 1.11.1
Version: 1.11.3
Authors@R: c(
person("Kevin", "Blighe", role = c("aut", "cre"), email = "kevin@clinicalbioinformatics.co.uk"),
person("Sharmila", "Rana", role = c("aut")),
Expand Down
33 changes: 21 additions & 12 deletions R/EnhancedVolcano.R
Expand Up @@ -89,10 +89,13 @@
#' @param typeConnectors Have the arrow head open ('open') or filled ('closed')?
#' @param endsConnectors Which end of connectors to draw arrow head? ('last',
#' 'first', 'both').
#' @param lengthConnectors Length of the connectors.
#' @param colConnectors Line colour of connectors.
#' @param maxoverlapsConnectors Equivalent of max.overlaps in ggrepel. Set to
#' @param lengthConnectors Length (size) of the connector arrowheads.
#' @param colConnectors Line colour of connectors and line segments.
#' @param max.overlaps Equivalent of max.overlaps in ggrepel. Set to
#' 'Inf' to always display all labels when drawConnectors = TRUE.
#' @param maxoverlapsConnectors See max.overlaps.
#' @param min.segment.length When drawConnectors = TRUE, specifies the minimum
#' length of the connector line segments.
#' @param directionConnectors direction in which to draw connectors.
#' 'both', 'x', or 'y'.
#' @param arrowheads Logical, indicating whether or not to draw arrow heads or
Expand Down Expand Up @@ -238,7 +241,9 @@ EnhancedVolcano <- function(
endsConnectors = 'first',
lengthConnectors = unit(0.01, 'npc'),
colConnectors = 'grey10',
maxoverlapsConnectors = 15,
max.overlaps = 15,
maxoverlapsConnectors = NULL,
min.segment.length = 0,
directionConnectors = 'both',
arrowheads = TRUE,
hline = NULL,
Expand Down Expand Up @@ -268,6 +273,10 @@ EnhancedVolcano <- function(
geom_point <- geom_point_rast
}

if (!is.null(maxoverlapsConnectors)) {
max.overlaps <- maxoverlapsConnectors
}

i <- xvals <- yvals <- Sig <- NULL

toptable <- as.data.frame(toptable)
Expand Down Expand Up @@ -806,7 +815,8 @@ EnhancedVolcano <- function(
parse = parseLabels,
na.rm = TRUE,
direction = directionConnectors,
max.overlaps = maxoverlapsConnectors)
max.overlaps = max.overlaps,
min.segment.length = min.segment.length)

} else if (drawConnectors && !is.null(selectLab)) {

Expand All @@ -833,7 +843,8 @@ EnhancedVolcano <- function(
parse = parseLabels,
na.rm = TRUE,
direction = directionConnectors,
max.overlaps = maxoverlapsConnectors)
max.overlaps = max.overlaps,
min.segment.length = min.segment.length)

} else if (!drawConnectors && !is.null(selectLab)) {

Expand All @@ -843,8 +854,6 @@ EnhancedVolcano <- function(
aes(
label = subset(toptable,
!is.na(toptable[['lab']]))[['lab']]),
xlim = c(NA, NA),
ylim = c(NA, NA),
size = labSize,
check_overlap = TRUE,
colour = labCol,
Expand All @@ -861,8 +870,6 @@ EnhancedVolcano <- function(
aes(label = subset(toptable,
toptable[[y]] < pCutoff &
abs(toptable[[x]]) > FCcutoff)[['lab']]),
xlim = c(NA, NA),
ylim = c(NA, NA),
size = labSize,
check_overlap = TRUE,
colour = labCol,
Expand Down Expand Up @@ -903,7 +910,8 @@ EnhancedVolcano <- function(
parse = parseLabels,
na.rm = TRUE,
direction = directionConnectors,
max.overlaps = maxoverlapsConnectors)
max.overlaps = max.overlaps,
min.segment.length = min.segment.length)

} else if (drawConnectors && !is.null(selectLab)) {

Expand All @@ -930,7 +938,8 @@ EnhancedVolcano <- function(
parse = parseLabels,
na.rm = TRUE,
direction = directionConnectors,
max.overlaps = maxoverlapsConnectors)
max.overlaps = max.overlaps,
min.segment.length = min.segment.length)

} else if (!drawConnectors && !is.null(selectLab)) {

Expand Down
113 changes: 21 additions & 92 deletions README.md
Expand Up @@ -2,7 +2,7 @@ EnhancedVolcano: publication-ready volcano plots with enhanced colouring
and labeling
================
Kevin Blighe, Sharmila Rana, Myles Lewis
2021-05-15
2021-07-23

# Introduction

Expand Down Expand Up @@ -206,22 +206,19 @@ Reference: shape](http://sape.inf.usi.ch/quick-reference/ggplot2/shape)

![Adjust shape of plotted points.](README_files/figure-gfm/ex4b-1.png)

## Adjust p-value cut-off
## Adjust cut-off lines and add extra threshold lines

The lines that are drawn to indicate cut-off points are also modifiable.
The parameter ‘cutoffLineType’ accepts the following values: “blank”,
“solid”, “dashed”, “dotted”, “dotdash”, “longdash”, and “twodash”. The
colour and thickness of these can also be modified with ‘cutoffLineCol’
and ‘cutoffLineWidth’, respectively. To disable the lines, set either
and ‘cutoffLineWidth’. To disable the lines, set either
cutoffLineType=“blank” or cutoffLineWidth=0.

Also, by using pCutoffCol=‘padj’, we instruct *EnhancedVolcano* to
generate a traditonal volcano using nominal / un-adjusted p-values (or
whatever is passed as ‘y’), but using adjusted p-values as the cut-off.

Extra lines can also be added via ‘hline’ and ‘vline’ to display other
custom cut-offs. To make these more visible, we will also remove the
default gridlines (gridlines.major and gridlines.minor).
cut-offs.

To make these more visible, we will also remove the default gridlines.

``` r
EnhancedVolcano(res,
Expand All @@ -230,24 +227,21 @@ default gridlines (gridlines.major and gridlines.minor).
y = 'pvalue',
xlim = c(-6, 6),
title = 'N061011 versus N61311',
subtitle = paste0('p-value cutoff (red line) drawn ',
'at equivalent of adjusted p=0.0001'),
pCutoff = 0.0001,
pCutoffCol = 'padj',
pCutoff = 10e-12,
FCcutoff = 1.5,
pointSize = 3.0,
labSize = 6.0,
colAlpha = 1,
cutoffLineType = 'solid',
cutoffLineCol = 'red2',
cutoffLineWidth = 2.5,
cutoffLineType = 'blank',
cutoffLineCol = 'black',
cutoffLineWidth = 0.8,
hline = c(10e-20,
10e-20 * 10e-30,
10e-20 * 10e-60,
10e-20 * 10e-90),
hlineCol = c('black', 'black', 'black', 'black'),
hlineType = c('longdash', 'longdash', 'dotdash', 'dotdash'),
hlineWidth = c(0.4, 0.4, 0.8, 0.8),
hlineCol = c('pink', 'hotpink', 'purple', 'black'),
hlineType = c('solid', 'longdash', 'dotdash', 'dotted'),
hlineWidth = c(1.0, 1.5, 2.0, 2.5),
gridlines.major = FALSE,
gridlines.minor = FALSE)
```
Expand Down Expand Up @@ -280,6 +274,9 @@ legend text, label size, and icon size can also be modified.
legendIconSize = 5.0)
```

![Adjust legend position, size, and
text.](README_files/figure-gfm/ex6-1.png)

Note: to make the legend completely invisible, specify:

``` r
Expand Down Expand Up @@ -349,8 +346,9 @@ labelled.

## Draw labels in boxes

To improve label clarity, we can draw simple boxes around the plots
labels. This works much better when drawConnectors is also TRUE.
To improve label clarity, we can draw simple boxes around the plot’s
labels via *boxedLabels*. This works much better when drawConnectors is
also TRUE.

``` r
EnhancedVolcano(res,
Expand Down Expand Up @@ -759,76 +757,7 @@ and suggestions from:
- Emir Turkes
- Benjamin Ostendorf
- Cristian (github.com/ccruizm)
- Andrea Grioni

# Session info

``` r
sessionInfo()
```

## R version 4.0.3 (2020-10-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04.7 LTS
##
## Matrix products: default
## BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
## LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0
##
## locale:
## [1] LC_CTYPE=pt_BR.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB.UTF-8 LC_COLLATE=pt_BR.UTF-8
## [5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=pt_BR.UTF-8
## [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] grid parallel stats4 stats graphics grDevices utils
## [8] datasets methods base
##
## other attached packages:
## [1] pasilla_1.16.0 gridExtra_2.3
## [3] DESeq2_1.28.1 org.Hs.eg.db_3.11.4
## [5] AnnotationDbi_1.53.0 magrittr_2.0.1
## [7] airway_1.8.0 SummarizedExperiment_1.18.2
## [9] DelayedArray_0.14.1 matrixStats_0.57.0
## [11] Biobase_2.48.0 GenomicRanges_1.40.0
## [13] GenomeInfoDb_1.24.2 IRanges_2.22.2
## [15] S4Vectors_0.26.1 BiocGenerics_0.34.0
## [17] EnhancedVolcano_1.9.13 ggrepel_0.9.1
## [19] ggplot2_3.3.3 knitr_1.31
##
## loaded via a namespace (and not attached):
## [1] bitops_1.0-6 bit64_4.0.5 ash_1.0-15
## [4] RColorBrewer_1.1-2 tools_4.0.3 R6_2.5.0
## [7] KernSmooth_2.23-18 vipor_0.4.5 DBI_1.1.1
## [10] colorspace_2.0-0 withr_2.4.1 tidyselect_1.1.0
## [13] ggrastr_0.2.3 ggalt_0.4.0 bit_4.0.4
## [16] compiler_4.0.3 extrafontdb_1.0 isoband_0.2.3
## [19] labeling_0.4.2 scales_1.1.1 proj4_1.0-10.1
## [22] genefilter_1.70.0 stringr_1.4.0 digest_0.6.27
## [25] rmarkdown_2.6 XVector_0.28.0 pkgconfig_2.0.3
## [28] htmltools_0.5.1.1 extrafont_0.17 fastmap_1.1.0
## [31] highr_0.8 maps_3.3.0 rlang_0.4.10
## [34] RSQLite_2.2.3 generics_0.1.0 farver_2.0.3
## [37] BiocParallel_1.22.0 dplyr_1.0.3 RCurl_1.98-1.2
## [40] GenomeInfoDbData_1.2.3 Matrix_1.3-2 Rcpp_1.0.6
## [43] ggbeeswarm_0.6.0 munsell_0.5.0 lifecycle_0.2.0
## [46] stringi_1.5.3 yaml_2.2.1 MASS_7.3-53
## [49] zlibbioc_1.34.0 blob_1.2.1 crayon_1.3.4
## [52] lattice_0.20-41 splines_4.0.3 annotate_1.66.0
## [55] locfit_1.5-9.4 pillar_1.4.7 geneplotter_1.66.0
## [58] XML_3.99-0.5 glue_1.4.2 evaluate_0.14
## [61] vctrs_0.3.6 Rttf2pt1_1.3.8 gtable_0.3.0
## [64] purrr_0.3.4 assertthat_0.2.1 cachem_1.0.1
## [67] xfun_0.20 xtable_1.8-4 survival_3.2-7
## [70] tibble_3.0.1 beeswarm_0.2.3 memoise_2.0.0
## [73] ellipsis_0.3.1

# References

Blighe, Rana, and Lewis (2018)
- Quan Le (Yale University)

# Session info

Expand Down Expand Up @@ -865,7 +794,7 @@ sessionInfo()
## [11] Biobase_2.48.0 GenomicRanges_1.40.0
## [13] GenomeInfoDb_1.24.2 IRanges_2.22.2
## [15] S4Vectors_0.26.1 BiocGenerics_0.34.0
## [17] EnhancedVolcano_1.9.13 ggrepel_0.9.1
## [17] EnhancedVolcano_1.11.3 ggrepel_0.9.1
## [19] ggplot2_3.3.3 knitr_1.31
##
## loaded via a namespace (and not attached):
Expand Down
Binary file modified README_files/figure-gfm/ex10-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/ex11-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/ex12-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/ex13-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/ex14-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/ex15-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/ex16-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/ex5-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/ex7-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/ex9-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions inst/NEWS
@@ -1,3 +1,10 @@

CHANGES IN VERSION 1.12
------------------------
- added max.overlaps and min.segment.length to provide further control over
connectors. max.overlaps replaces maxoverlapsConnectors, but both can still
be used for legacy purposes

CHANGES IN VERSION 1.10
------------------------
- added functionality to parse expressions in labels via parseLabels (TRUE/FALSE)
Expand Down
3 changes: 2 additions & 1 deletion inst/unitTests/test_datatypes.r
Expand Up @@ -18,7 +18,8 @@ test_that('datatypes', {
colAlpha, colGradientBreaks, colGradientLimits, legendLabSize,
legendIconSize, encircleSize, encircleAlpha, shadeAlpha, shadeSize,
shadeBins, widthConnectors, lengthConnectors, maxoverlapsConnectors, hline,
hlineWidth, vline, vlineWidth, borderWidth), c('integer', 'double'))
hlineWidth, vline, vlineWidth, borderWidth, max.overlaps, min.segment.length),
c('integer', 'double'))
expect_gt(EnhancedVolcano(subtitleLabSize, captionLabSize, pCutoff,
cutoffLineWidth, FCcutoff, labhjust, labvjust,
shape, colAlpha, legendLabSize, legendIconSize, encircleSize, encircleAlpha,
Expand Down
15 changes: 11 additions & 4 deletions man/EnhancedVolcano.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4aff21e

Please sign in to comment.