Get access to all lessons in this course.
-
Advanced Data Wrangling
- Downloading and Importing Data
- Overview of Tidy Data
- Tidy Data Rule #1: Every Column is a Variable
- Tidy Data Rule #3: Every Cell is a Single Value
- Tidy Data Rule #2: Every Row is an Observation
- Changing Variable Types
- Dealing with Missing Data
- Advanced Summarizing
- Binding Data Frames
- Functions
- Data Merging
- Exporting Data
- Bring It All Together (Advanced Data Wrangling)
-
Advanced Data Visualization
- Best Practices in Data Visualization
- Tidy Data
- Pipe Data into ggplot
- Reorder Plots to Highlight Findings
- Line Charts
- Use Color to Highlight Findings
- Declutter
- Add Descriptive Labels to Your Plots
- Use Titles to Highlight Findings
- Use Annotations to Explain
- Tweak Spacing
- Create a Custom Theme
- Customize Your Fonts
- Try New Plot Types
- Bring it All Together (Advanced Data Visualization)
-
Quarto
- Advanced Markdown
- Advanced YAML and Code Chunk Options
- Tables
- Inline R Code
- Making Your Reports Shine: Word Edition
- Making Your Reports Shine: PDF Edition
- Making Your Reports Shine: HTML Edition
- Presentations
- Dashboards
- Websites
- Publishing Your Work
- Quarto Extensions
- Parameterized Reporting, Part 1
- Parameterized Reporting, Part 2
- Parameterized Reporting, Part 3
- Wrapping up Going Deeper with R
Going Deeper with R
Reorder Plots to Highlight Findings
This lesson is locked
This lesson is called Reorder Plots to Highlight Findings, part of the Going Deeper with R course. This lesson is called Reorder Plots to Highlight Findings, part of the Going Deeper with R course.
If the video is not playing correctly, you can watch it in a new window
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Your Turn
Make a bar chart that shows race/ethnicity in Beaverton SD 48J. As before, filter your data to only include 2018-2019 data and only include Beaverton SD 48J. Then, do the following:
Using the
reorder()
function, make a bar chart that shows the percent of race/ethnicity groups in descending orderMake the same bar chart using
mutate()
andfct_reorder()
to reorder the race/ethnicity groups
Learn More
I mention that the fct_reorder()
function comes from the forcats
package in the video. Here’s how the documentation lays out the goal of forcats
:
R uses factors to handle categorical variables, variables that have a fixed and known set of possible values. Factors are also helpful for reordering character vectors to improve display. The goal of the forcats package is to provide a suite of tools that solve common problems with factors, including changing the order of levels or the values.
As the tweet below demonstrates, using factors can be complicated.
making any bar graphs with factors/categories is still my least favorite thing in the world pic.twitter.com/Neg8qp9ueq
— Damie Pak (@pakdamie) May 12, 2020
If you want to dig into factors a bit more, start with Chapter 15 of R for Data Science and Chapter 10 of Stat 545.
I'd also suggest reading the 2017 article Wrangling Categorical Data in R by Amelia McNamara and Nicholas Horton. Amelia McNamara also gave a talk in 2019 at rstudio::conf about factors , which is very helpful.
You need to be signed-in to comment on this post. Login.
Alberto Espinoza
October 7, 2022
David, are there instances where you prefer to use reorder() vs. fct_reorder() or vice-versa? I understand both concepts but not sure in which situations to employ either. Or is it a matter of preference?