How to reorder factors in R (the easy way)

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ก.ค. 2024
  • In this video I show you the best way to reorder factors in R.
    You can use a simple trick with arrange and mutate or use stats::reorder() function. The forcats::fct_reorder() function makes reordering factors even easier. And if you ever want to reorder factors for multiple categories all at once you should be aware of tidytext::reorder_within() function in combination with facet_wrap().
    ⏱ Time Stamps ⌚
    0:00 - Intro and video overview
    0:30 - Reorder trick with arrange and mutate
    4:40 - Order factors with stats::reorder
    5:40 - Order factors with forcats::fct_reorder
    6:45 - Order for multiple variables with tidytext::reorder_within
    9:40 - Thank you Outro
    Background Music:
    • PARASITE EVE 2 SOUNDTR...
    Sound effects obtained from www.zapsplat.com/

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

  • @forrestoakley4882
    @forrestoakley4882 ปีที่แล้ว +2

    I've just discovered your channel. It is a real treasure. Thank you very much!!!!!

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

      Thanks for leaving a comment. I am glad you enjoy the content. It has been a long dream of mine to make TH-cam videos as I like teaching, statistics and R-programming. I wish I could produce more videos but I think the first 2 years have been only the beginning. A lot more to come. I hope you come along on the ride :)

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

      @@TheDataDigest I sure will!

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

      Same here! Great and really helped me understand this! THX! :)

  • @corylowe5557
    @corylowe5557 2 หลายเดือนก่อน

    Awesome!

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

    great video, just the right spped.

  • @seb5542
    @seb5542 6 หลายเดือนก่อน +1

    I've been using reorder() in my aes() to reorder a bar graph, and I've come into an issue where it has caused all my bars to appear on the Y axis. It's the only reordering tool that has worked. But I've found this problem to be incredibly annoying, especially since no one has spoken about it. And it doesn't flip any of the other bits of data, just the bars themselves.

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

      Hi seb, do you mind sending an example with the code to this email (question[at]thedatadigest[dot]email). I might have experienced something similar myself and can probably help. I found it safer to do the reordering before the plotting.

    • @seb5542
      @seb5542 6 หลายเดือนก่อน +1

      @@TheDataDigest thank you very much, I've sent an email. I really appreciate it. I can't find anything about my issue online.

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

      @@seb5542 What a weird little problem. I just answered your email and you simply switched the variables in the reorder function and and then in aes() as well for x and y-values. No biggy :)