Hello! Please help me. I'm new to R.
I wanted to make a horizontal stacked bar plot and I've tried placing the "coord_flip" code in my barplot code but I can't seem to get the horizontal orientation. Here is the data/code that I've used. Thank you!
library (ggplot2)
dat <- read.table(text = "Bin018 Bin038 Bin095 Bin029 Bin031
Polyketide 3 2 2 6 1
Non-Ribosomal_Peptides 1 8 6 9 7
Terpenoids 5 1 0 1 0
Anti-microbial_Peptides 3 2 4 5 8", header = TRUE)
dat <- barplot (as.matrix(dat),
main = "Cyanobacterial SM Biosynthesis Genes",
xlab = "TSF Cyanobacterial MAGs", ylab = "Abundance",
col=c("cyan1","coral1","seagreen2","mediumpurple1"),
legend.text = rownames(dat),
args.legend = list(title = "Secondary Metabolites", x = "topleft",
inset = c(0.05, 0))) +
coord_flip()
I see, thank you for your response and suggestion! :D