Highlight labelled points

This commit is contained in:
hadley 2016-08-17 11:25:00 -05:00
parent 344b5493a9
commit 8d20a69e65
1 changed files with 3 additions and 0 deletions

View File

@ -109,9 +109,12 @@ That helps a bit, but if you look closely in the top-left hand corner, you'll no
```{r} ```{r}
ggplot(mpg, aes(displ, hwy)) + ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(colour = class)) + geom_point(aes(colour = class)) +
geom_point(size = 3, shape = 1, data = best_in_class) +
ggrepel::geom_label_repel(aes(label = model), data = best_in_class) ggrepel::geom_label_repel(aes(label = model), data = best_in_class)
``` ```
Note the other handy technique here: I added a second layer of large, hollow points to highligh the points that I've labelled.
You can sometimes use the same idea to replace the legend with labels placed directly on the plot. It's not wonderful for this plot, but it isn't too bad. (`theme(legend.position = "none")` turns the legend off --- we'll talk about it more shortly). You can sometimes use the same idea to replace the legend with labels placed directly on the plot. It's not wonderful for this plot, but it isn't too bad. (`theme(legend.position = "none")` turns the legend off --- we'll talk about it more shortly).
```{r} ```{r}