Discrete -> continuous

This commit is contained in:
hadley 2016-07-31 10:41:35 -05:00
parent f10ac5f685
commit fb8f3e5884
2 changed files with 5 additions and 4 deletions

View File

@ -465,7 +465,7 @@ ggplot(data = smaller) +
geom_hex(aes(x = carat, y = price))
```
Another option is to bin one continuous variable so it acts like a categorical variable. Then you can use one of the techniques for visualising the combination of a discrete and a continuous variable that you learned about. For example, you could bin `carat` and then for each group, display a boxplot:
Another option is to bin one continuous variable so it acts like a categorical variable. Then you can use one of the techniques for visualising the combination of a categorical and a continuous variable that you learned about. For example, you could bin `carat` and then for each group, display a boxplot:
```{r}
ggplot(data = smaller, mapping = aes(x = carat, y = price)) +

View File

@ -195,12 +195,13 @@ ggplot(shapes, aes(x, y)) +
geom_point(mapping = aes(x = displ, y = hwy, color = "blue"))
```
1. Which variables in `mpg` are discrete? Which variables are continuous?
1. Which variables in `mpg` are categorical? Which variables are continuous?
(Hint: type `?mpg` to read the documentation for the dataset). How
can you see this information when you run `mpg`?
1. Map a continuous variable to `color`, `size`, and `shape`. How do
these aesthetics behave differently for discrete vs. continuous variables?
these aesthetics behave differently for categorical vs. continuous
variables?
1. What happens if you map the same variable across multiple aesthetics?
What happens if you map different variables across multiple aesthetics?
@ -354,7 +355,7 @@ knitr::include_graphics("images/visualization-geoms-3.png")
knitr::include_graphics("images/visualization-geoms-4.png")
```
Many geoms, like `geom_smooth()`, use a single geometric object to display multiple rows of data. For these geoms, you can set the `group` aesthetic to a discrete variable to draw multiple objects. ggplot2 will draw a separate object for each unique value of the grouping variable. In practice, ggplot2 will automatically group the data for these geoms whenever you map an aesthetic to a discrete variable (as in the `linetype` example). It is convenient to rely on this feature because the group aesthetic by itself does not add a legend or distinguishing features to the geoms.
Many geoms, like `geom_smooth()`, use a single geometric object to display multiple rows of data. For these geoms, you can set the `group` aesthetic to a categorical variable to draw multiple objects. ggplot2 will draw a separate object for each unique value of the grouping variable. In practice, ggplot2 will automatically group the data for these geoms whenever you map an aesthetic to a discrete variable (as in the `linetype` example). It is convenient to rely on this feature because the group aesthetic by itself does not add a legend or distinguishing features to the geoms.
```{r, fig.width = 3, fig.align = 'default', out.width = "33%"}
ggplot(data = mpg) +