การเรียงลำดับ factor ใหม่

ข้อมูลเชิงหมวดหมู่ใน Tidyverse

Emily Robinson

Data Scientist

แผนภูมิแท่งที่แกน x แสดงคำตอบ แกน y แสดงจำนวน และมีหัวข้อว่า "how often do you use NLP at work?" แท่งจากซ้ายไปขวาคือ most of the time, often, rarely และ sometimes

ข้อมูลเชิงหมวดหมู่ใน Tidyverse

กราฟที่แก้ไขแล้ว

ggplot(aes(nlp_frequency, 
            x = fct_relevel(response, 
            "Rarely", "Sometimes", "Often", "Most of the time"))) + 
        geom_bar()

แผนภูมิแท่งเดิม แต่เรียงลำดับใหม่จากซ้ายไปขวาเป็น rarely, sometimes, often, most of the time

ข้อมูลเชิงหมวดหมู่ใน Tidyverse

fct_reorder()

nlp_frequency %>%
    pull(response) %>%
    levels()
[1] "Most of the time" "Often" "Rarely" "Sometimes"       
nlp_frequency %>%
    mutate(response = fct_relevel(response, 
            "Often", "Most of the time")) %>%
    pull(response) %>%
    levels()
[1] "Often" "Most of the time" "Rarely" "Sometimes"
ข้อมูลเชิงหมวดหมู่ใน Tidyverse

อาร์กิวเมนต์เพิ่มเติม

nlp_frequency %>%
    mutate(response = fct_relevel(response, 
            "Often", "Most of the time", after = 2)) %>%
            pull(response) %>%
            levels()
nlp_frequency %>%
    mutate(response = fct_relevel(response, 
            "Often", "Most of the time", after = Inf) %>%
    pull(response) %>%
    levels()
[1] "Rarely" "Sometimes" "Often" "Most of the time"
ข้อมูลเชิงหมวดหมู่ใน Tidyverse

มาฝึกกันเถอะ!

ข้อมูลเชิงหมวดหมู่ใน Tidyverse

Preparing Video For Download...