I was trying to use ggplot2 to creat a percentage barplot.
An example dataframe
sample mapped(%) unmapped(%) reads
sample1 96.5 3.5 1320
sample2 97.4 2.6 1451
sample3 92.1 7.9 1824
sample4 98.7 1.3 1563
and I used following code to create the barplot
df <- algin %>% gather(col,reads,mapped:reads)
ggplot(df,aes(x=sample, y=reads, fill=col)) + geom_col(position = position_stack()) + coord_flip() + scale_fill_manual("legend", values = c("mapped" = "darkred", "unmapped" = "red", "reads"="darkblue"))
Although the created barplot here is close to what I desired to display, it doesn't seem like correct, e.g. legend should be "mapped" with darkblue color, "unmapped" with darkred color.
I set above values as I tried different settings, and only above one gave me the desired visual effect.
For example, I also tried
ggplot(df, aes(x = sample, y = reads, fill = col)) +
geom_col(position = position_stack()) +
coord_flip() +
scale_fill_manual(
"legend",
values = c("mapped" = "darkblue", "unmapped" = "darkred", "reads" = "red")
)
What I want to see is
- bar length represents
reads(sequencing reads) of each sample, and add every x-axis values with M unit, e.g. 500M, 1000M, etc; - darkblue color corresponds to the percentage of reads that were aligned (i.e.
mapped) to the reference genome; - darkred color corresponds to the percentage of reads that were not aligned (i.e.
unmapped) to the reference genome; - legend: mapped, unmapped, and better to remove reads (as is no necessary to be there)
An example of the desired plot as follows

Solutions appreciated!
Thanks!



