Improving the appearance of a stacked barchart with ggplot2, dplyr, and forcats (CC103)

Поделиться
HTML-код
  • Опубликовано: 14 июл 2024
  • Sometimes we don't have a choice in the type of data visualization format we use. Although a stacked barchart is not ideal, there are methods for improving the appearance of stacked barcharts. In this episode of Code Club, Pat uses ggplot2, dplyr, and forcats to show how to pool rare taxa and order the more abundant taxa to give a common anchor point on the y-axis to make comparisons.
    Pat will use RStudio and functions from the tidyverse including #ggplot2, #dplyr, and #forcats packages. The accompanying blog post can be found at www.riffomonas.org/code_club/....
    Do you have a figure that you would like to receive a critique or help improving? Let me know and I'd be happy to arrange a guest appearance!
    If you're interested in taking an upcoming 3 day R workshop, email me at riffomonas@gmail.com!
    R: r-project.org
    RStudio: rstudio.com
    Raw data: github.com/riffomonas/raw_dat...
    Workshops: www.mothur.org/wiki/workshops
    You can also find complete tutorials for learning R with the tidyverse using...
    Microbial ecology data: www.riffomonas.org/minimalR/
    General data: www.riffomonas.org/generalR/
    0:00 Introduction
    4:16 Pooling rare phyla
    8:36 Specifying order of stacked bars w/ help of forcats
    14:41 Changing colors and appearance of legend
    17:33 Making bars sit on x-axis
    18:15 Critique of figure
    21:28 Recap
  • НаукаНаука

Комментарии • 33

  • @Riffomonas
    @Riffomonas  3 года назад +3

    Without using a different chart type, what else would you do to improve the appearance of these stacked bar charts?

    • @erickcardenas6055
      @erickcardenas6055 3 года назад +1

      You can facet by taxa with scales=free_y.

    • @trevorjgould
      @trevorjgould 3 года назад +1

      @@erickcardenas6055 then sort facets so highest mean y is first.

  • @liliabkar
    @liliabkar Год назад

    Thanks for sharing these.very helpful!!

  • @sven9r
    @sven9r 3 года назад +1

    amazing videos! glad I found your stuff! greetings from germany :)

    • @Riffomonas
      @Riffomonas  3 года назад

      My pleasure - thanks for watching!

  • @cristianjaviermena6955
    @cristianjaviermena6955 11 месяцев назад

    THE MANNNNNNN thanks a lot

  • @david6661997
    @david6661997 2 года назад +1

    Interesting, I'm back to R and study how write code, this video is useful for start to make charts with weather information, thanks for your video was very helpful.

    • @Riffomonas
      @Riffomonas  2 года назад +1

      My pleasure. Thanks for watching!

  • @yaqinguo8971
    @yaqinguo8971 3 года назад +1

    great video. Thanks

  • @julianrozenberg2036
    @julianrozenberg2036 2 года назад +2

    Well, the.beauty of you presentations is that you not only learn R.... Actually, what I learn is English😃😃😃

    • @Riffomonas
      @Riffomonas  2 года назад

      Ha! That’s wonderful to hear. Thanks for watching 🤓

  • @johnschloss694
    @johnschloss694 3 года назад +2

    Nice vid!

  • @mikodine
    @mikodine Год назад +1

    Love stacked bar charts! What alternative do you prefer?

  • @johnschloss694
    @johnschloss694 3 года назад +2

    nice vid

  • @ndipagbor7280
    @ndipagbor7280 2 года назад +1

    Thank you so much for your lectures. They really help me understand the basics of R.
    I have a questions concerning barcharts in ggplot2. Is there a way to place the bars and tick labels between the tick marks rather than on them? This is possible in excel. It will be nice to replicate that in R

    • @Riffomonas
      @Riffomonas  2 года назад +1

      I know it’s possible. Probably would involve using the theme function on the major and minor axis ticks

    • @ndipagbor7280
      @ndipagbor7280 2 года назад

      @@Riffomonas Thank you so much. I'll try that again and see what I get.

  • @thorbjornf.8873
    @thorbjornf.8873 Год назад

    Thanks a lot! Is there a way (not manually) to reorder the stacked bar plots in a specific/ascending order of the most abundant taxa (Firmicutes)? Leaving Healthy on the left, changing the position of Diarrhea pos. to middel and Diarrhea neg. to the right?

    • @Riffomonas
      @Riffomonas  Год назад +2

      Thanks for watching! Just to be clear - I hate stacked bar charts 😂 You could make the disease status a factor and order the factor by whatever you want

  • @minhtrungdang1853
    @minhtrungdang1853 Год назад +1

    Thank you for the video. What will we do if we want to sort bar in order. For example, we want to put Fermicute at the bottom and the mean will increase in the order : Healthy, Diarrhea C difficile positive, and Diarrhea C difficile negative ?

    • @Riffomonas
      @Riffomonas  Год назад +1

      Keep watching the later episodes in that series where I cover that. Still, I strongly encourage using side by side bars/boxes over stacked bars

    • @minhtrungdang1853
      @minhtrungdang1853 Год назад

      @@Riffomonas Thank you ! what post you discuss on this issue? I used stacked bar chart and side by side when I need two

    • @Riffomonas
      @Riffomonas  Год назад

      @@minhtrungdang1853 ruclips.net/video/w4X3o6MQjVA/видео.html

  • @user-oj6lo7xx7m
    @user-oj6lo7xx7m 11 месяцев назад

    Would it be better to separate the phyla into their own graphs and look at them separately? Like different facets or grids? One for each Phyla?

    • @Riffomonas
      @Riffomonas  3 месяца назад

      Hopefully you found my other videos, but my preference woudl be to put the taxa on the x-axis and cluster the treatment groups within each taxa. Then represent the individual samples with a jitter plot

  • @christophschweingruber936
    @christophschweingruber936 Год назад

    Great videos! You can simplify the pooling of taxa with forcats::fct_lump functions into one step, which I find really handy.

  • @muhammadrahmanalishah6188
    @muhammadrahmanalishah6188 2 года назад +1

    how we calculate percentage of each sample.. can you tell me..?

    • @Riffomonas
      @Riffomonas  2 года назад +1

      I forget what I did here but you should be able to group by the sample and then look at the count divided by the sum of the counts for each group to get the relative abundance. Multiply by 100 to get the percentage

    • @muhammadrahmanalishah6188
      @muhammadrahmanalishah6188 2 года назад

      @@Riffomonas Thank you so much