Fix typos (#199)

This commit is contained in:
behrman 2016-07-28 06:04:50 -07:00 committed by Hadley Wickham
parent 3104dbfca0
commit 22d207508f
1 changed files with 12 additions and 12 deletions

View File

@ -65,9 +65,9 @@ ggplot(data = mpg) +
With ggplot2, you begin a plot with the function `ggplot()`. `ggplot()` creates a coordinate system that you can add layers to. The first argument of `ggplot()` is the dataset to use in the graph. So `ggplot(data = mpg)` creates an empty graph, but it's not very interesting so I'm not going to show it here.
You complete your graph by adding one or more layers to `ggplot()`. The function `geom_point()` adds a layer of points to your plot, which creates a scatterplot. ggplot2 comes with many geom functions that each add a different type of layer to a plot. You'll learn a whole bunch of them through out this chapter.
You complete your graph by adding one or more layers to `ggplot()`. The function `geom_point()` adds a layer of points to your plot, which creates a scatterplot. ggplot2 comes with many geom functions that each add a different type of layer to a plot. You'll learn a whole bunch of them throughout this chapter.
Each geom function in ggplot2 takes a `mapping` argument. This defines how variables in your dataset are mapped to visual properties. You must always use `mapping()` in conjunction with `aes()`. The `x` and `y` arguments of `aes()` describe which variables to map to the x and y axes of your plot, and ggplot2 will look for those variables in your dataset, `mpg`.
Each geom function in ggplot2 takes a `mapping` argument. This defines how variables in your dataset are mapped to visual properties. You must always use `mapping` in conjunction with `aes()`. The `x` and `y` arguments of `aes()` describe which variables to map to the x and y axes of your plot, and ggplot2 will look for those variables in your dataset, `mpg`.
Let's turn this code into a reusable template for making graphs with ggplot2. To make a graph, replace the bracketed sections in the code below with a dataset, a geom function, or a set of mappings.
@ -129,7 +129,7 @@ ggplot(data = mpg) +
To map an aesthetic to a variable, set the name of the aesthetic to the name of the variable inside `aes()`. ggplot2 will automatically assign a unique level of the aesthetic (here a unique color) to each unique value of the variable, a process known as __scaling__. ggplot2 will also add a legend that explains which levels correspond to which values.
The colors reveal that many of the unusual points are two seater cars. These cars don't seem like hybrids, and are, in fact, sports cars! Sports cars have large engines like SUVs and pickup trucks, but small bodies like midsize and compact cars, which improves their gas mileage. In hindsight, these cars were unlikely to be hybrids since they have large engines.
The colors reveal that many of the unusual points are two-seater cars. These cars don't seem like hybrids, and are, in fact, sports cars! Sports cars have large engines like SUVs and pickup trucks, but small bodies like midsize and compact cars, which improves their gas mileage. In hindsight, these cars were unlikely to be hybrids since they have large engines.
In the above example, we mapped `class` to the color aesthetic, but we could have mapped `class` to the size aesthetic in the same way. In this case, the exact size of each point would reveal its class affiliation. We get a _warning_ here, because mapping an unordered variable (`class`) to an ordered aesthetic (`size`) is not a good idea.
@ -213,7 +213,7 @@ ggplot(shapes, aes(x, y)) +
1. Vignettes are long-form guides the documentation things about
a package that affect many functions. ggplot2 has two vignettes.
How can you find them and what do they describe? (Hint: google is
How can you find them and what do they describe? (Hint: Google is
your friend.)
## Common problems
@ -229,9 +229,9 @@ ggplot(data = mpg)
+ geom_point(mapping = aes(x = displ, y = hwy))
```
If you're still stuck, try the help. You can get help about any R function by runnning `?function_name` in the console, or selecting the function name and pressing F1 in RStudio. Don't worry if the help doesn't seem that helpful - instead skip down to the examples and look for code that matches what you're trying to do.
If you're still stuck, try the help. You can get help about any R function by running `?function_name` in the console, or selecting the function name and pressing F1 in RStudio. Don't worry if the help doesn't seem that helpful - instead skip down to the examples and look for code that matches what you're trying to do.
If that doesn't help, carefully read the error message. Sometimes the answer will be buried there! But when you're new to R, the answer might be in the error message but you don't yet know how to understand it. Another great tool is google: trying googling the error message, as it's likely someone else has had the same problem, and have gotten help online.
If that doesn't help, carefully read the error message. Sometimes the answer will be buried there! But when you're new to R, the answer might be in the error message but you don't yet know how to understand it. Another great tool is Google: trying googling the error message, as it's likely someone else has had the same problem, and have gotten help online.
## Facets
@ -333,7 +333,7 @@ ggplot(data = mpg) +
geom_smooth(mapping = aes(x = displ, y = hwy, linetype = drv))
```
Here `geom_smooth()` separates the cars into three lines based on their `drv` value, which describes a car's drivetrain. One line describes all of the points with a `4` value, one line describes all of the points with an `f` value, and one line describes all of the points with an `r` value. Here, `4` stands for four wheel drive, `f` for front wheel drive, and `r` for rear wheel drive.
Here `geom_smooth()` separates the cars into three lines based on their `drv` value, which describes a car's drivetrain. One line describes all of the points with a `4` value, one line describes all of the points with an `f` value, and one line describes all of the points with an `r` value. Here, `4` stands for four-wheel drive, `f` for front-wheel drive, and `r` for rear-wheel drive.
If this sounds strange, we can make it more clear by overlaying the lines on top of the raw data and then coloring everything according to `drv`.
@ -500,7 +500,7 @@ Stats are the most subtle part of plotting because you can't see them directly.
```{r}
demo <- tibble::tibble(
a = c("bar_1","bar_2","bar_3"),
a = c("bar_1", "bar_2", "bar_3"),
b = c(20, 30, 40)
)
demo
@ -640,10 +640,10 @@ To learn more about a position adjustment, look up the help page associated with
Coordinate systems are probably the most complicated part of ggplot2. The default coordinate system is the Cartesian coordinate system where the x and y position act independently to find the location of each point.
There are a number of other coordinate systems that are occassionally helpful.
There are a number of other coordinate systems that are occasionally helpful.
* `coord_flip()` switches the x and y axes. This is useful (for example),
if you want vertical boxplots.
if you want horizontal boxplots.
```{r fig.width = 3, out.width = "50%", fig.align = "default"}
ggplot(data = mpg, mapping = aes(x = class, y = hwy)) +
@ -668,7 +668,7 @@ There are a number of other coordinate systems that are occassionally helpful.
coord_quickmap()
```
* `coord_polar()` uses polar coordinates. Polar coordinates reveals an
* `coord_polar()` uses polar coordinates. Polar coordinates reveal an
interesting connection between a bar chart and a Coxcomb chart.
```{r fig.width = 3, out.width = "50%", fig.align = "default", fig.asp = 1}
@ -711,7 +711,7 @@ knitr::include_graphics("images/visualization-coordinate-systems.png")
## The layered grammar of graphics
In the previous sections, you learned much more than how to make scatterplots, bar charts, and boxplots. You learned a foundation that you can use to make _any_ type of plot with ggplot2. To see this, lets add position adjustments, stats, coordinate systems, and faceting to our code template:
In the previous sections, you learned much more than how to make scatterplots, bar charts, and boxplots. You learned a foundation that you can use to make _any_ type of plot with ggplot2. To see this, let's add position adjustments, stats, coordinate systems, and faceting to our code template:
```
ggplot(data = <DATA>) +