Skip to content
R for the Rest of Us Logo

Reorder Plots to Highlight Findings

This lesson is locked

Get access to all lessons in this course.


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:

  1. Using the reorder() function, make a bar chart that shows the percent of race/ethnicity groups in descending order

  2. Make the same bar chart using mutate() and fct_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.

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.

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Alberto Espinoza

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

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.