0

I currently have a stacked barplot with the data how I want it, other than the fact I am unsure of how to add percentage labels to break down how much of each sample belongs to each color/category.

I just need to know what packages/code would be helpful in adding the percentages so I can see the specific breakdown of the last two columns in particular.

I have the following code and plot:

tbl10 = read.table("combinedtest.Q")
names1 = read.table("names_sorted.txt")[,1]
bp=barplot(t(as.matrix(tbl10)), col=c("aliceblue","antiquewhite","aquamarine","black","blue","blue4","blueviolet","brown1","brown4","cadetblue","chartreuse","chocolate1","coral1","cornflowerblue","cyan","darkgoldenrod1","darkgray","darkgreen","darkmagenta","darkolivegreen1","hotpink","darkseagreen2","darkslateblue","deeppink","firebrick1","khaki1"),xlab="", ylab="Ancestry", border=NA)
text(cex=1, x=bp, y=-.08, names1, xpd=TRUE, srt=90)

output

QAsena
  • 603
  • 4
  • 9
  • 1
    This is likely a dupe of https://stackoverflow.com/q/12018499/3358272, https://stackoverflow.com/q/6455088/3358272, and https://stackoverflow.com/q/74636143/3358272. Your last two columns are going to be a problem due to the density of the different stacked bars; for this, you _might_ be able to use `ggrepel::geom_text_repel`, though I suspect you'll have to spend a lot of time finessing the x-limits, and find other ways to keep all of the labels clear. (`ggrepel` may not be best here.) – r2evans Feb 06 '23 at 16:45

0 Answers0