From the course: Learning the R Tidyverse
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
forcats for manipulating factors - R Tutorial
From the course: Learning the R Tidyverse
forcats for manipulating factors
- The forcats package is part of a core Tidyverse and it simplifies absolutely everything about working with factors. It will change your life compared to base R, however, you might well be completely new to factors. So let's get to grips with both factors and the forcats package by opening up the 05_04b project. Here I am in a forcats.r script. We're going to load the Tidyverse on line one and then I've got some code here to make a ggplot2 chart of the M sleep dataset and it's going to show me the different kinds of diets of the animals in the M Sleep dataset. Now what determines the order in which the bars are displayed? Do you know? Well, let's print M sleep. Well, let's actually print this part of a code of a console. So we can see that this tibble contains a vore, an N column, and a vore column is a character column. So all that ggplot2 can do is use character order to determine the order of the bars. So the bars are shown in reverse alphabetical order. NA is a little bit…