Entering edit mode
Hello Community experts: I have a script to make a volcano plot (ggplot) on logFC and Pval cutoffs, and it works well as such. I was wondering if someone can help me figure our how to actually put the number of selected entities (i.e. genes, selected based on cutoff) itself in the plot legend?
For e.g. LEGEND in volcano figure
Up regulated [#355] Down regulated [#162] Not significant [#3567]
Thank you. NS
omics<-read_xlsx("file.xlsx")
omics.df<-data.frame(omics)
omics.df<- omics.df[,c(1,2,3)] #excel sets for ID, log2FC and PVal columns
colnames(omics.df) <- c('ID','AR', 'PVal')
up.fc = 1.5
down.fc = -1.5
pVal.cutoff = 0.05
up.genes <- omics.df[omics.df$AR > 1.5 & omics.df$PVal < 0.05, 1:3]
down.genes <- omics.df[omics.df$AR < -1.5 & omics.df$PVal < 0.05, 1:3]
omics.df$volcanoColor="Nonsignificant"
omics.df$volcanoColor[omics.df$Symbol %in% up.genes$Symbol]<-"Upregulated"
omics.df$volcanoColor[omics.df $Symbol %in% down.genes$Symbol]<-"Downregulated"
omics.df$volcanoLabel = F
omics.df$volcanoLabel[omics.df$Symbol %in% up.genes$Symbol]<- T
omics.df$volcanoLabel[omics.df$Symbol %in% down.genes$Symbol]<-T
cols<- c("Nonsignificant" = "gray", "Upregulated" = "red", "Downregulated" = "green")
omics.df_VP<-(ggplot(omics.df, aes(x = (AR), y = -log10(PVal))) +
ggtitle("25 microM") +
scale_colour_manual(values = cols) +
geom_point(aes(colour = volcanoColor)) +
xlab(expression(log[2]("Fold Change"))) +
ylab(expression(-log[10]("Adjusted PVal"))) +
annotate("text", x = c(-4.25,4), y = 20, label=c("218 proteins downregulated","316 proteins upregulated"), size = rel(11) ,col=c("darkgreen","darkred")) +
scale_y_continuous(limits = c(0,10)) +
theme(text = element_text(face = "bold", family = "Arial"),
plot.title = element_text(hjust = .55, size = rel(2.75)),
panel.background = element_rect(fill = "white"),
legend.position = "none",
axis.text.y = element_text(size = rel(3)),
axis.text.x = element_text(size = rel(3)),
axis.title = element_text(size = rel(2.75))) +
theme(legend.position = "bottom", plot.title = element_text(hjust = 0.5, size = 27),
legend.text = element_text(size = 25),
legend.title = element_blank(),
panel.background = element_rect(fill = "white"),
legend.text.align = 0,
legend.title.align = 0,
axis.title = element_text(size = rel(4.0))) +
geom_hline(yintercept = -log10(pVal.cutoff), colour="darkred", linetype="dashed") + geom_vline(xintercept = (up.fc), colour="darkred", linetype="dashed") + geom_vline(xintercept = (down.fc), colour="darkred", linetype="dashed"))
omics.df_VP