How to create Multi-Panel plots in R with facet_wrap() and facet_grid()

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ค. 2024
  • In this video, I will show you how to use facet_wrap or facet_grid to create multi-panel plots in R and ggplot.
    Faceting plots can be very helpful to compare your data over different categories.
    It can also help you to get a quick overview of your data across multiple variables if you use a special pivot longer trick.
    ⏱ Time Stamps ⌚
    0:00 - Intro
    1:20 - gapminder example
    5:09 - facet_wrap arguments
    9:35 - facet_grid
    13:54 - pivot_longer trick
    22:02 - ggarrange
    External Links:
    www.r-bloggers.com/2018/03/di...
    www.r-bloggers.acom/2023/02/s...

ความคิดเห็น • 14

  • @ignaciosanchez1983
    @ignaciosanchez1983 11 หลายเดือนก่อน +2

    Great video! Keep going

  •  ปีที่แล้ว +4

    Great in-depth video, excellent content.

    • @TheDataDigest
      @TheDataDigest  ปีที่แล้ว

      Thanks for watching, liking and commenting :)
      I wanted to include as much as possible without being to long or boring. Next video will be about pie charts.

  • @icefunkdark8555
    @icefunkdark8555 10 หลายเดือนก่อน +2

    This video is so useful. Thank you so much for sharing :) Appreciate the content and time.

    • @TheDataDigest
      @TheDataDigest  10 หลายเดือนก่อน +1

      And thank you for taking the time to leave such a nice comment. It is really motivating for me, to see that other people find my content useful :)

  • @greenone9951
    @greenone9951 11 หลายเดือนก่อน

    scale_x_reordered function seems useful

  • @GaboMoya
    @GaboMoya 10 หลายเดือนก่อน +1

    I have a question. How do u change the order of the desplay. The factet grid follows alphabetical order. But i need and special order. For example the order in min 7:09 its Africa, Americas, Asia, Europe. But what if u want Europe first?

    • @TheDataDigest
      @TheDataDigest  10 หลายเดือนก่อน

      You have to use the factor() function and provide a new order of the levels. For example like this:
      gapminder$continent2

    • @TheDataDigest
      @TheDataDigest  10 หลายเดือนก่อน

      Just for transparency: I orginally used "labels" but it has to be "levels" otherwise the Africa data just got re-labeld with Europe instead of ordering the levels new.

    • @TheDataDigest
      @TheDataDigest  10 หลายเดือนก่อน

      I have a dedicated video about reordering factors: th-cam.com/video/ChhJUN1JDLI/w-d-xo.html

  • @91lovemusic
    @91lovemusic 26 วันที่ผ่านมา

    14:19 i still fail doing that chart 😅

    • @TheDataDigest
      @TheDataDigest  วันที่ผ่านมา

      What error message are you getting? Did you load the tidytext package to have the reorder_within() function available?

  • @Zoyfad
    @Zoyfad ปีที่แล้ว +1

    thanks for the video:)
    btw dplyr::slice_ functions are nice
    diamonds %>%
    slice_sample(n = 5000)

    • @TheDataDigest
      @TheDataDigest  11 หลายเดือนก่อน +1

      Thanks for the feedback. Really great to have someone that posts some extra useful functions. I knew the slice() function and remember now using it in the past after arrange to only select the top 3 of something. But wasn't aware that there is slice_sample(). So thanks again :)