Skip to content

Commit e1f1dc9

Browse files
move slice_min/max back to viz where it appears first
1 parent cc80767 commit e1f1dc9

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

source/classification1.Rmd

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,7 @@ the $K=5$ neighbors that are nearest to our new point.
460460
You will see in the `mutate` \index{mutate} step below, we compute the straight-line
461461
distance using the formula above: we square the differences between the two observations' perimeter
462462
and concavity coordinates, add the squared differences, and then take the square root.
463-
In order to find the $K=5$ nearest neighbors, we will use the `slice_min` function.
464-
465-
> **Note:** Recall that in Chapter \@ref(intro), we used `arrange` followed by `slice` to
466-
> obtain the ten rows with the *largest* values of a variable. We could have instead used
467-
> the `slice_max` function for this purpose. The `slice_min` and `slice_max` functions
468-
> achieve the same goal as `arrange` followed by `slice`, but are slightly more efficient
469-
> because they are specialized for this purpose. In general, it is good to use more specialized
470-
> functions when they are available!
463+
In order to find the $K=5$ nearest neighbors, we will use the `slice_min` function. \index{slice\_min}
471464

472465
```{r 05-multiknn-1, echo = FALSE, fig.height = 3.5, fig.width = 4.5, fig.pos = "H", out.extra="", fig.cap="Scatter plot of concavity versus perimeter with new observation represented as a red diamond."}
473466
perim_concav <- bind_rows(cancer,

source/viz.Rmd

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -922,10 +922,18 @@ are hard to distinguish, and the names of the landmasses are obscuring each
922922
other as they have been squished into too little space. But remember that the
923923
question we asked was only about the largest landmasses; let's make the plot a
924924
little bit clearer by keeping only the largest 12 landmasses. We do this using
925-
the `slice_max` function. Then to give the labels enough
925+
the `slice_max` function: the `order_by` argument is the name of the column we
926+
want to use for comparing which is largest, and the `n` argument specifies how many
927+
rows to keep. Then to give the labels enough
926928
space, we'll use horizontal bars instead of vertical ones. We do this by
927-
swapping the `x` and `y` variables:
928-
\index{slice\_max}
929+
swapping the `x` and `y` variables:\index{slice\_max}\index{slice\_min}
930+
931+
> **Note:** Recall that in Chapter \@ref(intro), we used `arrange` followed by `slice` to
932+
> obtain the ten rows with the largest values of a variable. We could have instead used
933+
> the `slice_max` function for this purpose. The `slice_max` and `slice_min` functions
934+
> achieve the same goal as `arrange` followed by `slice`, but are slightly more efficient
935+
> because they are specialized for this purpose. In general, it is good to use more specialized
936+
> functions when they are available!
929937
930938
```{r 03-data-islands-bar-2, warning=FALSE, message=FALSE, fig.width=5, fig.height=2.75, fig.align = "center", fig.pos = "H", out.extra="", fig.cap = "Bar plot of size for Earth's largest 12 landmasses."}
931939
islands_top12 <- slice_max(islands_df, order_by = size, n = 12)

0 commit comments

Comments
 (0)