12
12
# ' @param comparison Name of contrast to plot. If given, it's assumed that \code{lfc.col=paste0(comparison, '.logFC')}
13
13
# ' and \code{sig.col=paste0(comparison, '.p') or paste0(comparison, '.FDR')}, and these are over-ridden.
14
14
# ' @param name Name of PNG file to write to. Set to \code{NA} to suppress writing to file.
15
- # ' @param add .rnames Additional rownames of features to annotate. These must be in \code{rownames(tab)}.
15
+ # ' @param ann .rnames Additional rownames of \code{tab} to annotate; must be in \code{rownames(tab)}.
16
16
# ' @param up.color Color for points that are upregulated (\code{logFC>0}).
17
17
# ' @param down.color Color for points that are downregulated (\code{logFC<0}).
18
18
# ' @param x.bound x-axis limits are set to \code{c(-x.bound, x.bound)}. If \code{NULL, x.bound=max(abs(tab[,lfc.col]))}.
19
19
# ' @param y.bound y-axis limits are set to \code{c(0, y.bound)}. If \code{NULL, y.bound=max(tab[,'nlg10sig'])}.
20
20
# ' @param type.sig Type of significance y-axis should use, either "p" or "FDR".
21
21
# ' @param cut.color Color of points that meet both \code{cut.lfc} and \code{cut.sig}. If \code{NULL}, cutoffs are ignored.
22
22
# ' @param cut.lfc Points need to have \code{|logFC| >= cut.lfc} to have \code{cut.color}.
23
- # ' @param cut.sig Points need to have significance \code{<= cut.sig} to have \code{cut.color}. Significance type is of
24
- # ' \code{type.sig}.
23
+ # ' @param cut.sig Points need to have significance \code{tab[,sig.col] <= cut.sig} to have \code{cut.color}.
25
24
# ' @param sep Separator string between contrast names and suffix such as \code{logFC}.
26
25
# ' @param na.lab Character vector of labels in \code{lab.col} to treat as missing, in addition to \code{NA}.
27
26
# ' @details If \code{ntop.sig>0} or \code{ntop.lfc>0}, then \code{lab.col} must be in \code{colnames(tab)}.
28
27
# ' @return A ggplot object, invisibly.
29
28
# ' @export
30
29
31
- ezvolcano <- function (tab , lfc.col = NULL , sig.col = NULL , lab.col = ' Gene.Symbol ' , ntop.sig = 0 , ntop.lfc = 0 , comparison = NULL ,
32
- name = ' volcano' , add .rnames= NULL , up.color = ' black' , down.color = ' black' , x.bound = NULL , y.bound = NULL ,
30
+ ezvolcano <- function (tab , lfc.col = NULL , sig.col = NULL , lab.col = NULL , ntop.sig = 0 , ntop.lfc = 0 , comparison = NULL ,
31
+ name = ' volcano' , ann .rnames= NULL , up.color = ' black' , down.color = ' black' , x.bound = NULL , y.bound = NULL ,
33
32
type.sig = c(' p' , ' FDR' ), cut.color = NULL , cut.lfc = 1 , cut.sig = 0.05 , sep = ' .' , na.lab = c(' ---' , ' ' )){
34
33
if (! requireNamespace(" ggplot2" , quietly = TRUE )){
35
34
stop(" Package 'ggplot2' needed for this function to work. Please install it." , call. = FALSE )
@@ -44,9 +43,9 @@ ezvolcano <- function(tab, lfc.col=NULL, sig.col=NULL, lab.col='Gene.Symbol', nt
44
43
ntop.sig <- 0
45
44
warning(" ntop.sig > 0 but lab.col is null." )
46
45
}
47
- if (! is.null(add .rnames )){
48
- add .rnames <- NULL
49
- warning(" add .rnames is not null, but lab.col is null." )
46
+ if (! is.null(ann .rnames )){
47
+ ann .rnames <- NULL
48
+ warning(" ann .rnames is not null, but lab.col is null." )
50
49
}
51
50
}
52
51
@@ -69,8 +68,9 @@ ezvolcano <- function(tab, lfc.col=NULL, sig.col=NULL, lab.col='Gene.Symbol', nt
69
68
}
70
69
71
70
stopifnot((ntop.sig == 0 & ntop.lfc == 0 ) | lab.col %in% colnames(tab ), ntop.sig == as.integer(ntop.sig ),
72
- ntop.lfc == as.integer(ntop.lfc ), is.null(add.rnames )| add.rnames %in% rownames(tab ),
73
- lfc.col %in% colnames(tab ), sig.col %in% colnames(tab ), any(tab [,lfc.col ]< 0 ), any(tab [,lfc.col ]> = 0 ))
71
+ ntop.lfc == as.integer(ntop.lfc ), is.null(ann.rnames )| ann.rnames %in% rownames(tab ),
72
+ lfc.col %in% colnames(tab ), sig.col %in% colnames(tab ), any(tab [,lfc.col ]< 0 ), any(tab [,lfc.col ]> = 0 ),
73
+ length(x.bound )< = 1 , length(y.bound )< = 1 )
74
74
75
75
tab <- data.frame (tab , nlg10sig = - log10(tab [,sig.col ]))
76
76
# want symmetric x-axis
@@ -99,13 +99,14 @@ ezvolcano <- function(tab, lfc.col=NULL, sig.col=NULL, lab.col='Gene.Symbol', nt
99
99
if (ntop.sig > 0 ) top.sig.ind <- order(tab [,sig.col ])[1 : ntop.sig ] else top.sig.ind <- NULL
100
100
ind.annot <- setdiff(union(top.sig.ind , top.lfc.ind ), na.lab.ind )
101
101
}
102
- # add .rnames to plot with symbol
103
- if (! is.null(add .rnames )){
104
- ind.add .rnames <- which(rownames(tab ) %in% add .rnames )
105
- ind.annot <- union(ind.add .rnames , ind.annot )
102
+ # ann .rnames to plot with symbol
103
+ if (! is.null(ann .rnames )){
104
+ ind.ann .rnames <- which(rownames(tab ) %in% ann .rnames )
105
+ ind.annot <- union(ind.ann .rnames , ind.annot )
106
106
}
107
107
if (! is.null(ind.annot )){
108
- vol <- vol + ggplot2 :: geom_text(data = tab [ind.annot ,], mapping = ggplot2 :: aes_string(x = lfc.col , y = ' nlg10sig' , label = lab.col ), size = 3 , vjust = 2 )
108
+ vol <- vol + ggplot2 :: geom_text(data = tab [ind.annot ,], mapping = ggplot2 :: aes_string(x = lfc.col , y = ' nlg10sig' , label = lab.col ),
109
+ size = 3 , vjust = 2 )
109
110
}
110
111
111
112
if (! is.na(name )) ggplot2 :: ggsave(filename = paste0(name , " .png" ), plot = vol ) else graphics :: plot(vol )
0 commit comments