Polish ordered factors
This commit is contained in:
parent
8e2430817f
commit
8dc95f9c6d
|
@ -414,7 +414,7 @@ Read the documentation to learn about `fct_lump_min()` and `fct_lump_prop()` whi
|
|||
## Ordered factors
|
||||
|
||||
Before we go on, there's a special type of factor that needs to be mentioned briefly: ordered factors.
|
||||
Ordered factors, created with `ordered()`, imply a strict ordering of levels such that the first level is "less than" the second level and so on.
|
||||
Ordered factors, created with `ordered()`, imply a strict ordering and equal distance between levels: the first level is "less than" the second level by the same amount that the second level is "less than" the third level, and so on..
|
||||
You can recognize them when printing because they use `<` between the factor levels:
|
||||
|
||||
```{r}
|
||||
|
@ -422,9 +422,9 @@ ordered(c("a", "b", "c"))
|
|||
```
|
||||
|
||||
In practice, `ordered()` factors behave very similarly to regular factors.
|
||||
There are only two places where you might notice different behaviour:
|
||||
There are only two places where you might notice different behavior:
|
||||
|
||||
- If you map an ordered factor to color or fill in ggplot2, it will default to `scale_color_viridis()`/`scale_fill_viridis()`, a color scale that implies a ranking.
|
||||
- If you use an ordered function in a linear model, it will use "polygonal contrasts". These are midly useful, but you are unlikely to have heard of them unless you have a PhD in Statistics, and even then you probably don't routinely interpret them.
|
||||
- If you use an ordered function in a linear model, it will use "polygonal contrasts". These are mildly useful, but you are unlikely to have heard of them unless you have a PhD in Statistics, and even then you probably don't routinely interpret them.
|
||||
|
||||
Given the arguable utility of these differences, we don't generally recommend using ordered factors.
|
||||
|
|
Loading…
Reference in New Issue