-
Notifications
You must be signed in to change notification settings - Fork 0
/
volcano-plot-ggplotly.R
40 lines (33 loc) · 1.2 KB
/
volcano-plot-ggplotly.R
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
# Libraries required
library(plotly)
library(dplyr)
library(tidyverse)
library(lazyeval)
library(ggplot2)
data_volcano <- read.delim("data.txt", stringsAsFactors = FALSE)
str(data_volcano)
volcano_plot_interactive <- function (data, logFC, pvalue, annotation, plotname) {
require(dplyr)
require(lazyeval)
require(plotly)
logFC <- enquo(logFC)
pvalue <- enquo(pvalue)
annotation <- enquo(annotation)
data1<- data %>%
mutate(group = case_when(
(abs(!!logFC) > 1 & !!pvalue > 0.05) ~ "|logFC| > 1",
(abs(!!logFC) < 1 & !!pvalue < 0.05) ~ "pval < 0.05",
(abs(!!logFC) > 1 & !!pvalue < 0.05) ~ "|logFC| >1 & pval < 0.05",
TRUE ~ "NS"
))
gg<- ggplot(data1, aes(x=!!logFC, y=-log10(!!pvalue), color = group, text = !!annotation)) +
geom_point()+
theme_minimal()+
labs(x= "log Fold Change", y = "-log10(adjusted pvalue)")
ggp <- ggplotly(gg, tooltip = "text")
name_file <- paste(plotname,".html", collapse = NULL)
htmlwidgets::saveWidget(as_widget(ggp), name_file)
}
# volcano plots:
# data - logFC column - pvalue column - on hover annotation - plot name
volcano_plot_interactive(data_volcano, LIMMA_logFC, LIMMA_adj.P.Val, Gene.names, "intvolcanoplot")