-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathvolcano.Rmd
76 lines (70 loc) · 1.65 KB
/
volcano.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
title: "Volcano plot with the ability to query snp codes"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(plotly)
library(htmlwidgets)
vline <- function(x = 1) {
list(
type = "line",
x1 = x, x0 = x, xref = "x",
y0 = 0, y1 = 1, yref = "paper",
line = list(dash = "dash")
)
}
hline <- function(y = 4) {
list(
type = "line",
y0 = y, y1 = y, yref = "y",
x1 = 0, x0 = 1, xref = "paper",
line = list(dash = "dash")
)
}
data(HapMap, package = "manhattanly")
HapMap %>%
mutate(P2 = -log10(P)) %>%
plot_ly(
x = ~EFFECTSIZE, y = ~ P2, text = ~SNP, hoverinfo = "text",
customdata = ~paste0("https://www.ncbi.nlm.nih.gov/snp/?term=", SNP)
) %>%
add_markers(color = I("black"), alpha = 0.1) %>%
# add annotations for the upper-right quadrant
add_fun(
function(plot) {
plot %>%
filter(EFFECTSIZE > 1 & P2 > 2) %>%
add_markers(color = I("red")) %>%
add_annotations(text = ~SNP)
}
) %>%
# add annotations for the upper-left quadrant
add_fun(
function(plot) {
plot %>%
filter(EFFECTSIZE < -1 & P2 > 2) %>%
add_markers(color = I("blue")) %>%
add_annotations(text = ~SNP)
}
) %>%
toWebGL() %>% # webgl renders many points much more efficiently!
layout(
showlegend = FALSE,
shapes = list(
vline(-1),
vline(1),
hline(2)
),
xaxis = list(zeroline = FALSE),
yaxis = list(zeroline = FALSE)
) %>%
onRender("function(el, x) {
el.on('plotly_click', function(d) {
var url = d.points[0].customdata;
window.open(url);
});
}")
```