Get access to all lessons in this course.
-
Advanced Data Wrangling and Analysis
- Overview
- Importing Data
- Tidy Data
- Reshaping Data
- Dealing with Missing Data
- Changing Variable Types
- Advanced Variable Creation
- Advanced Summarizing
- Binding Data Frames
- Functions
- Merging Data
- Renaming Variables
- Quick Interlude to Reorganize our Code
- Exporting Data
-
Advanced Data Visualization
- Data Visualization Best Practices
- Tidy Data
- Pipe Data Into ggplot
- Reorder Plots to Highlight Findings
- Line Charts
- Use Color to Highlight Findings
- Declutter
- Use the scales Package for Nicely Formatted Values
- Use Direct Labeling
- Use Axis Text Wisely
- Use Titles to Highlight Findings
- Use Color in Titles to Highlight Findings
- Use Annotations to Explain
- Tweak Spacing
- Customize Your Theme
- Customize Your Fonts
- Try New Plot Types
-
Advanced RMarkdown
- Advanced Markdown Text Formatting
- Tables
- Advanced YAML
- Inline R Code
- Making Your Reports Shine: Word Edition
- Making Your Reports Shine: HTML Edition
- Making Your Reports Shine: PDF Edition
- Presentations
- Dashboards
- Other Formats
-
Wrapping Up
- You Did It!
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.
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?
David Keyes
October 7, 2022
I always use fct_reorder(). It's part of the forcats package and that package gives you a ton of options to reorder in different ways.