setGeneric(
name = 'volcanoPlot',
def = function(p.value,
fc,
p.cutoff = 0.05,
fc.cutoff = 1.3,
xlab = 'Log2 (Fold change)',
ylab = '-Log10 (P-value)') {
p.value <- as.numeric(p.value)
fc <- as.numeric(fc)
marker <- rep('No', length(p.value))
marker[p.value < p.cutoff &
fc > fc.cutoff] <- 'Increase'
marker[p.value < p.cutoff &
fc < 1 / fc.cutoff] <- 'Decrease'
data <-
data.frame(p.value, fc, marker, stringsAsFactors = FALSE)
require(ggplot2)
plot <- ggplot(data, aes(log(fc, 2), -log(p.value, 10),
colour = marker)) +
geom_point() +
scale_colour_manual(
guide = guide_legend(title = NULL),
values = c(
'No' = 'grey',
'Increase' = '#ED00007F',
'Decrease' = '#00468B7F'
)
) +
theme_bw() +
geom_hline(yintercept = -log(p.cutoff, 10),
linetype = 2) +
geom_vline(xintercept = c(log(fc.cutoff, 2), -log(fc.cutoff, 2)), linetype = 2) +
labs(x = xlab, y = ylab) +
theme(
axis.title = element_text(size = 15),
axis.text = element_text(size = 12),
legend.title = element_text(size = 15),
legend.text = element_text(size = 12),
legend.position = c(1, 1),
legend.justification = c(1, 1),
legend.background = element_rect(fill = NULL, colour = 'black')
)
plot
}
)
将这个函数放在R中source,然后只要提供算好的fold change和p value即可。
运行代码如下:
volcanoPlot(p.value = p.value, fc = fc)
得出图如下:
可以看到颜色配色不太好看,可以尝试使用别人已经弄好的主题或者配色。主题推荐使用ggthemes包,里面有很多不同的主题。配色推荐使用ggsci包,里面给出了不同杂志的配色方案。比如我们使用jama的配色方案,就可以得到下面的图:
plot + ggsci::scale_color_jama()
联系客服