Discuss ggplot2 call transition
This commit is contained in:
parent
512305365f
commit
fc99e2d633
25
EDA.Rmd
25
EDA.Rmd
|
@ -554,3 +554,28 @@ ggplot(data = diamonds2, mapping = aes(x = cut, y = resid)) +
|
|||
```
|
||||
|
||||
Modelling is important because once you have recognised a pattern, a model allows you to make that pattern quantitative and precise, and partition it out from what remains. That supports a powerful interative approach where you indentify a pattern with visualisation, then subtract with a model, allowing you to see the subtler trends that remain. I deliberately chose not to teach modelling yet, because understanding what models are and how they work are easiest once you have some other tools in hand: data wrangling, and programming.
|
||||
|
||||
## ggplot2 calls
|
||||
|
||||
As we move on from these introductory chapters, we'll transition to a more concise expression of ggplot2 code. So far we've been very explicit, which is helpful when you are learning:
|
||||
|
||||
```{r, eval = FALSE}
|
||||
ggplot(data = faithful, mapping = aes(x = eruptions)) +
|
||||
geom_histogram(binwidth = 0.25)
|
||||
```
|
||||
|
||||
But the first couple of arguments to a function are typically so important that you should know them by heart. The first two arguments to `ggplot()` are `data` and `mapping`, and the first two arguments to `aes()` are `x` and `y`. In the remainder of the book, we won't supply those names. That saves typing and by reducing the amount of boilerplate makes it easier to see what's different between plots (that's a rely important programming concern that we'll come back in [functions]).
|
||||
|
||||
```{r, eval = FALSE}
|
||||
ggplot(faithful, aes(eruptions)) +
|
||||
geom_histogram(binwidth = 0.25)
|
||||
```
|
||||
|
||||
Sometimes we'll turn the end of pipeline of data transformation into a plot. Watch for the transition from `%>%` to `+`. I wish this transition wasn't necessary but unfortunately ggplot2 was created before the pipe was discovered.
|
||||
|
||||
```{r, eval = FALSE}
|
||||
diamonds %>%
|
||||
count(cut, clarity) %>%
|
||||
ggplot(aes(clarity, cut, fill = n)) +
|
||||
geom_tile()
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue