Entering edit mode
5.6 years ago
2405592M
▴
150
Hi guys. I'm working with a data set and I've written a for loop that generates barplots for my input tRNA data. I've been able to generate my bar plots. However, I have a column with my P values and I want to annotate on my bar plots any significant log fold changes (Padj<=0.05) with an asterisk, and insignificant values (Padj>0.05) with NS. How do I do this and incorporate it into my for loop. Been stuck on this all weekend. THANKS IN ADVANCE!!!
*head(df) ...
Isodecoder Anticodon Loci Fragment_type Label LFC Padj
1 Ala AGC 1 wholecounts Ala-AGC-1-wholecounts 3.6111408 8.890000e-10
2 Ala AGC 10 wholecounts Ala-AGC-10-wholecounts 0.3910508 6.404589e-01
3 Ala AGC 12 wholecounts Ala-AGC-12-wholecounts NA NA
4 Ala AGC 2 wholecounts Ala-AGC-2-wholecounts 0.2785932 4.741744e-01
5 Ala AGC 3 wholecounts Ala-AGC-3-wholecounts 1.3492899 3.269910e-04
6 Ala AGC 4 wholecounts Ala-AGC-4-wholecounts -0.4200119 1.475002e-01
*This is my current code:
df <- read.delim("/mnt/data/wholecounts_barplot_input.txt", stringsAsFactors = FALSE)
library(ggplot2)
plot_list <- list()
for (iso in c("Ala", "Arg", "Asn", "Asp", "Cys", "Gln", "Glu", "Gly", "His", "Ile", "Leu", "Lys", "Met", "Phe", "Pro", "SeC", "Ser", "Thr", "Trp", "Tyr", "Val", "iMet")) {
df2 <- subset(df, Isodecoder == iso)
temp_plot <- ggplot(data = df2, aes(x = Label, y = LFC, fill = Anticodon))+
geom_bar(stat = "identity")+
xlab("tRNA")+
ylab("Log2FC")+
ylim(c(-2, 4))+
theme_bw()+
theme(axis.text.x = element_text(size = 12, angle = 45, hjust = 1), plot.margin = margin(0.5,0.5,0.5,2, "cm"))+
ggtitle(iso, "Full Length tRNA LFCs")
plot_list[[iso]] <- temp_plot
pdf(paste(iso, "wholecounts_LFCs.pdf", sep = "_"), bg = "white", width = 15, height = 7)
print(temp_plot)
dev.off()
}
Can you do this for boxplots also?