Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

barplot with ggplot fill by a column of dataframe

I was trying to create a barplot using a column of dataframe to fill the bars, but the bars result empty.
the head of my df dataframe (13.000 rows) is this:

  head(metadata)
                                membership condition timepoint                 rep            barcode
   AAACAGCCACCTGCTC-1           3          WT        d3                        r1                      AAACAGCCACCTGCTC-1
   AAACATGCAGGAATCG-1           4          WT        d3                        r1                      AAACATGCAGGAATCG-1
   AAACCAACAATATAGG-1           3          KO        d3                        r1                      AAACCAACAATATAGG-1
   AAACCGAAGCGAGTAA-1           3          KO        d3                        r1                      AAACCGAAGCGAGTAA-1
   AAACCGAAGCGATAAG-1           3          KO        d5                        r1                      AAACCGAAGCGATAAG-1
   AAACCGAAGGATAAAC-1           4          KO        d5                        r1                      AAACCGAAGGATAAAC-1

What I’ve tried is:

    ggplot(metadata, aes(x=treatment, fill=membership)) + geom_bar(position = "fill") +
        theme(axis.text.x=element_text(angle=45, hjust=1)) +  geom_hline(yintercept = 0.50)

but the result is: enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

while I was expecting the bars filled by the distributions of clusters (membership) in the two conditions. Here I plot an example of what I want to do:enter image description here

>Solution :

It could be because the membership column is numerical, make sure it to be factor/character.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading