Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make labCol order consistent with selectLabs #108

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Authors@R: c(
person("Emir", "Turkes", role = c("ctb")),
person("Benjamin", "Ostendorf", role = c("ctb")),
person("Andrea", "Grioni", role = c("ctb")),
person("Myles", "Lewis", role = c("aut")))
person("Myles", "Lewis", role = c("aut")),
person("Tianyi", "Shi", role = c("ctb"))),
Maintainer: Kevin Blighe <[email protected]>
Description: Volcano plots represent a useful way to visualise the results of differential expression analyses. Here, we present a highly-configurable function that produces publication-ready volcano plots. EnhancedVolcano will attempt to fit as many point labels in the plot window as possible, thus avoiding 'clogging' up the plot with labels that could not otherwise have been read. Other functionality allows the user to identify up to 4 different types of attributes in the same plot space via colour, shape, size, and shade parameter configurations.
License: GPL-3
Expand Down
194 changes: 28 additions & 166 deletions R/EnhancedVolcano.R
Original file line number Diff line number Diff line change
Expand Up @@ -796,56 +796,26 @@ EnhancedVolcano <- function(
plot <- plot + theme(panel.grid.minor = element_blank())
}

# user has specified to draw with geom_text or geom_label?
if (!boxedLabels) {

# For labeling with geom_[text|label]_repel and
# geom_[text|label] with check_overlap = TRUE, 4 possible
# scenarios can arise
if (drawConnectors && is.null(selectLab)) {

if (arrowheads) {
arr <- arrow(length = lengthConnectors,
type = typeConnectors, ends = endsConnectors)
} else {
arr <- NULL
}

plot <- plot + geom_text_repel(
data = subset(toptable,
toptable[[y]] < pCutoff &
abs(toptable[[x]]) > FCcutoff),
aes(label = subset(toptable,
toptable[[y]] < pCutoff &
abs(toptable[[x]]) > FCcutoff)[["lab"]]),
xlim = c(NA, NA),
ylim = c(NA, NA),
size = labSize,
segment.color = colConnectors,
segment.size = widthConnectors,
arrow = arr,
colour = labCol,
fontface = labFace,
parse = parseLabels,
na.rm = TRUE,
direction = directionConnectors,
max.overlaps = max.overlaps,
min.segment.length = min.segment.length)

} else if (drawConnectors && !is.null(selectLab)) {
if (arrowheads) {
arr <- arrow(length = lengthConnectors,
type = typeConnectors, ends = endsConnectors)
} else {
arr <- NULL
}

if (arrowheads) {
arr <- arrow(length = lengthConnectors,
type = typeConnectors, ends = endsConnectors)
} else {
arr <- NULL
}
lab_data <- if (is.null(selectLab)) {
subset(toptable, toptable[[y]] < pCutoff &
abs(toptable[[x]]) > FCcutoff)
} else {
table_sel <- subset(toptable, !is.na(toptable$lab))
table_sel[order(factor(table_sel$lab, levels = selectLab)),]
}

plot <- plot + geom_text_repel(
data = subset(toptable,
!is.na(toptable[['lab']])),
aes(label = subset(toptable,
!is.na(toptable[['lab']]))[['lab']]),
geom_volcano_lab <- function(fn, fn_repel, data){
if (drawConnectors) {
fn_repel(
data = lab_data,
aes(label = lab),
xlim = c(NA, NA),
ylim = c(NA, NA),
size = labSize,
Expand All @@ -859,132 +829,24 @@ EnhancedVolcano <- function(
direction = directionConnectors,
max.overlaps = max.overlaps,
min.segment.length = min.segment.length)

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

plot <- plot + geom_text(
data = subset(toptable,
!is.na(toptable[['lab']])),
aes(
label = subset(toptable,
!is.na(toptable[['lab']]))[['lab']]),
size = labSize,
check_overlap = TRUE,
colour = labCol,
fontface = labFace,
parse = parseLabels,
na.rm = TRUE)

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

plot <- plot + geom_text(
data = subset(toptable,
toptable[[y]] < pCutoff &
abs(toptable[[x]]) > FCcutoff),
aes(label = subset(toptable,
toptable[[y]] < pCutoff &
abs(toptable[[x]]) > FCcutoff)[['lab']]),
} else {
fn(
data = lab_data,
aes(label = lab),
size = labSize,
check_overlap = TRUE,
colour = labCol,
fontface = labFace,
parse = parseLabels,
na.rm = TRUE)
}

}

# user has specified to draw with geom_text or geom_label?
plot <- plot + if (!boxedLabels) {
geom_volcano_lab(geom_text, geom_text_repel)
} else {

# For labeling with geom_[text|label]_repel and
# geom_[text|label] with check_overlap = TRUE, 4 possible
# scenarios can arise
if (drawConnectors && is.null(selectLab)) {

if (arrowheads) {
arr <- arrow(length = lengthConnectors,
type = typeConnectors, ends = endsConnectors)
} else {
arr <- NULL
}

plot <- plot + geom_label_repel(
data = subset(toptable,
toptable[[y]] < pCutoff &
abs(toptable[[x]]) > FCcutoff),
aes(label = subset(toptable,
toptable[[y]]<pCutoff &
abs(toptable[[x]]) > FCcutoff)[['lab']]),
xlim = c(NA, NA),
ylim = c(NA, NA),
size = labSize,
segment.color = colConnectors,
segment.size = widthConnectors,
arrow = arr,
colour = labCol,
fontface = labFace,
parse = parseLabels,
na.rm = TRUE,
direction = directionConnectors,
max.overlaps = max.overlaps,
min.segment.length = min.segment.length)

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

if (arrowheads) {
arr <- arrow(length = lengthConnectors,
type = typeConnectors, ends = endsConnectors)
} else {
arr <- NULL
}

plot <- plot + geom_label_repel(
data = subset(toptable,
!is.na(toptable[['lab']])),
aes(label = subset(toptable,
!is.na(toptable[['lab']]))[['lab']]),
xlim = c(NA, NA),
ylim = c(NA, NA),
size = labSize,
segment.color = colConnectors,
segment.size = widthConnectors,
arrow = arr,
colour = labCol,
fontface = labFace,
parse = parseLabels,
na.rm = TRUE,
direction = directionConnectors,
max.overlaps = max.overlaps,
min.segment.length = min.segment.length)

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

plot <- plot + geom_label(
data = subset(toptable,
!is.na(toptable[["lab"]])),
aes(
label = subset(toptable,
!is.na(toptable[['lab']]))[['lab']]),
size = labSize,
colour = labCol,
fontface = labFace,
parse = parseLabels,
na.rm = TRUE)

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

plot <- plot + geom_label(
data = subset(toptable,
toptable[[y]] < pCutoff &
abs(toptable[[x]]) > FCcutoff),
aes(label = subset(toptable,
toptable[[y]] < pCutoff &
abs(toptable[[x]]) > FCcutoff)[['lab']]),
size = labSize,
colour = labCol,
fontface = labFace,
parse = parseLabels,
na.rm = TRUE)

}
geom_volcano_lab(geom_label, geom_label_repel)
}

# encircle
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ and suggestions from:
- Benjamin Ostendorf
- Cristian (github.com/ccruizm)
- Quan Le (Yale University)
- Tianyi Shi (github.com/TianyiShi2001)

# Session info

Expand Down