How to label the points(genes) I want in the plot?
modified 19-05-09
VolcanoView_want <- function(df, x = "logFC", y = "adj.P.Val", Label = NA, top = 5,topnames = gene_you_want, filename = NULL, x_cutoff = log2(1.5), y_cutoff = 0.05,main = NULL, xlab = "Log2 Fold Change", ylab = "-Log10(P.value)", ...){
requireNamespace("ggrepel", quietly=TRUE) || stop("need ggrepel package")
gg = df
gg$group="gray80"
gg[, y] = -log10(gg[, y])
gg$Label <- ""
gg$Label[toupper(gg$Official) %in% topnames] <- dd1$Official[toupper(gg$Official) %in% topnames]
gg$group[which(toupper(gg$Official) %in% topnames)] <- "#e41a1c"
idx = unique(which(gg$Label %in% topnames))
gg$Label = as.character(gg$Label)
ggplot(gg,aes(x = LFC, y = FDR, lablel = Label) )+
geom_jitter(position = "jitter", show.legend = FALSE, alpha=0.8, size = 0.5)+
theme(text = element_text(colour="black",size = 14, family = "Helvetica"),
plot.title = element_text(hjust = 0.5, size=16),
axis.text = element_text(colour="gray10"))+
theme(axis.line = element_line(size=0.5, colour = "black"),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.border = element_blank(), panel.background = element_blank())+
labs(x=xlab, y=ylab, title=main) + xlim(-4.5,0)+
geom_text_repel(aes(x=gg[,'LFC'],y=gg[,'FDR'], label = Label), data=gg,
fontface = 'bold', size = 4,
box.padding = unit(0.4, "lines"), segment.color = '#D8DBE2',
point.padding = unit(0.3, "lines"), segment.size = 0.3)+
theme(legend.position = "none")+
geom_point(aes(x=gg[,x], y=gg[,y]),color = ifelse(gg$Label == "","#D8DBE2", "red"))
if(!is.null(filename)){
ggsave(plot=p, filename=filename, units = "in")
}
return(p)
}
网友评论