-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_methods.R
More file actions
83 lines (78 loc) · 4.21 KB
/
Copy pathplot_methods.R
File metadata and controls
83 lines (78 loc) · 4.21 KB
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
77
78
79
80
81
###
# Created on Mon Oct 15
# @author: zheng zhang
# @purpose: to plot finger print annotation files by classes
# a customized version of ChemRICH interactive and impact plot for ucsd use
# @notice: This two methods are modified based on ChemRICHFunctions.R
# @reference: Barupal, D.K. and Fiehn, ChemRICH, (2017)
# GitHub repository, https://github.com/barupal/ChemRICH
#
# @input: dataframe prepared using prepareXlogp.R and prepare_form.py
# @output: plots (static:png, interactive:html) in the folder plots
###
# x-axis represents classes xlogp values (median xlogpg of all the class members)
# y_axis represents classes -log(classes pvalues)
# color code: class upratio (found using fold change)
# red -> class upratio = 1
# blue -> class upratio = 0
impactPlot <- function(inputdf) {
p2 <- ggplot(inputdf,aes(x=class_xlogp,y=-log(pvalue)))
p2 <- p2 + geom_point(aes(size=csize, color=upratio)) +
scale_color_gradient(low = "blue", high = "red", limits=c(0,1))+
scale_size(range = c(3, 10)) +
scale_y_continuous("-log (pvalue)",limits = c(0, max(-log(inputdf$pvalue))+4 )) +
scale_x_continuous(" median XlogP of clusters ") +
theme_bw() +
geom_label_repel(aes(label = classes), color = "gray20",family="Arial",data=subset(inputdf, csize>2),force = 5)+
theme(text=element_text(family="Arial Black"))+
theme(
plot.title = element_text(face="bold", size=30,hjust = 0.5),
axis.title.x = element_text(face="bold", size=20),
axis.title.y = element_text(face="bold", size=20, angle=90),
panel.grid.major = element_blank(), # switch off major gridlines
panel.grid.minor = element_blank(), # switch off minor gridlines
legend.position = "none", # manually position the legend (numbers being from 0,0 at bottom left of whole plot to 1,1 at top right)
legend.title = element_blank(), # switch off the legend title
legend.text = element_text(size=12),
legend.key.size = unit(1.5, "lines"),
legend.key = element_blank(), # switch off the rectangle around symbols in the legend
legend.spacing = unit(.05, "cm"),
axis.text.x = element_text(size=10,angle = 0, hjust = 1),
axis.text.y = element_text(size=15,angle = 0, hjust = 1)
)
dir.create(file.path('plots'), showWarnings = FALSE)
setwd(file.path('plots'))
ggsave(paste0(project_name,"_impact_plot.png"), p2,height = 8, width = 12, dpi=300)
setwd("..")
}
interactivePlot <- function(clusterdf) {
p2 <- ggplot(inputdf,aes(label=classes,label2=pvalue, label3=csize,label4=compounds_names))
p2 <- p2 + geom_point(aes(x=class_xlogp,y=-log(pvalue),size=csize*0.1, color=upratio)) +
scale_color_gradient(low = "blue", high = "red", limits=c(0,1))+
scale_size(range = c(5, 30)) +
scale_y_continuous("-log (pvalue)",limits = c(0, max(-log(inputdf$pvalue))+5 )) +
scale_x_continuous(" median XlogP of clusters ") +
theme_bw() +
#labs(title = "ChemRICH cluster impact plot") +
geom_text(aes(x=class_xlogp,y=-log(pvalue),label = classes), color = "gray20",data=subset(inputdf, csize>2))+
theme(
plot.title = element_text(face="bold", size=30,hjust = 0.5),
axis.title.x = element_text(face="bold", size=20),
axis.title.y = element_text(face="bold", size=20, angle=90),
panel.grid.major = element_blank(), # switch off major gridlines
panel.grid.minor = element_blank(), # switch off minor gridlines
legend.position = "none", # manually position the legend (numbers being from 0,0 at bottom left of whole plot to 1,1 at top right)
legend.title = element_blank(), # switch off the legend title
legend.text = element_text(size=12),
legend.key.size = unit(1.5, "lines"),
legend.key = element_blank(), # switch off the rectangle around symbols in the legend
legend.spacing = unit(.05, "cm"),
axis.text.x = element_text(size=15,angle = 0, hjust = 1),
axis.text.y = element_text(size=15,angle = 0, hjust = 1)
)
gg <- ggplotly(p2,tooltip = c("label","label2","label4"), width = 1600, height = 1000)
dir.create(file.path('plots'), showWarnings = FALSE)
setwd(file.path('plots'))
saveWidget(gg,file = paste0(project_name, "_interactive.html"), selfcontained = T)
setwd("..")
}