Some fixes for chapters regexps & factors (#1636)

* regexps.qmd: fix name of 'too_few' arg

* regexps.qmd: fix typo

* factors.qmd: update argument names to .f, .x, .y

* factors.qmd: fix language
This commit is contained in:
Floris Vanderhaeghe 2024-03-02 02:12:26 +01:00 committed by GitHub
parent 33e701227a
commit f55997b961
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -177,9 +177,9 @@ It is hard to read this plot because there's no overall pattern.
We can improve it by reordering the levels of `relig` using `fct_reorder()`.
`fct_reorder()` takes three arguments:
- `f`, the factor whose levels you want to modify.
- `x`, a numeric vector that you want to use to reorder the levels.
- Optionally, `fun`, a function that's used if there are multiple values of `x` for each value of `f`. The default value is `median`.
- `.f`, the factor whose levels you want to modify.
- `.x`, a numeric vector that you want to use to reorder the levels.
- Optionally, `.fun`, a function that's used if there are multiple values of `.x` for each value of `.f`. The default value is `median`.
```{r}
#| fig-alt: |
@ -231,7 +231,7 @@ Reserve `fct_reorder()` for factors whose levels are arbitrarily ordered.
However, it does make sense to pull "Not applicable" to the front with the other special levels.
You can use `fct_relevel()`.
It takes a factor, `f`, and then any number of levels that you want to move to the front of the line.
It takes a factor, `.f`, and then any number of levels that you want to move to the front of the line.
```{r}
#| fig-alt: |
@ -247,7 +247,7 @@ ggplot(rincome_summary, aes(x = age, y = fct_relevel(rincome, "Not applicable"))
Why do you think the average age for "Not applicable" is so high?
Another type of reordering is useful when you are coloring the lines on a plot.
`fct_reorder2(f, x, y)` reorders the factor `f` by the `y` values associated with the largest `x` values.
`fct_reorder2(.f, .x, .y)` reorders the factor `.f` by the `.y` values associated with the largest `.x` values.
This makes the plot easier to read because the colors of the line at the far right of the plot will line up with the legend.
```{r}
@ -287,7 +287,7 @@ Combine it with `fct_rev()` if you want them in increasing frequency so that in
```{r}
#| fig-alt: |
#| A bar char of marital status ordered in from least to most common:
#| A bar char of marital status ordered from least to most common:
#| no answer (~0), separated (~1,000), widowed (~2,000), divorced
#| (~3,000), never married (~5,000), married (~10,000).
gss_cat |>

View File

@ -265,7 +265,7 @@ df |>
)
```
If the match fails, you can use `too_short = "debug"` to figure out what went wrong, just like `separate_wider_delim()` and `separate_wider_position()`.
If the match fails, you can use `too_few = "debug"` to figure out what went wrong, just like `separate_wider_delim()` and `separate_wider_position()`.
### Exercises
@ -336,7 +336,7 @@ That lets you avoid one layer of escaping:
str_view(x, r"{\\}")
```
If you're trying to match a literal `.`, `$`, `|`, `*`, `+`, `?`, `{`, `}`, `(`, `)`, there's an alternative to using a backslash escape: you can use a character class: `[.]`, `[$]`, `[|]`, \...
If you're trying to match a literal `.`, `$`, `|`, `*`, `+`, `?`, `{`, `}`, `(`, `)`, there's an alternative to using a backslash escape: you can use a character class: `[.]`, `[$]`, `[|]`, ...
all match the literal values.
```{r}