This gives us a useful way of displaying more than two variables in a two-dimensional plot. When making a scatterplot with geom_point we are not limited to specifying the x and y coordinates of each point we can also specify the size and color of each point. For example, in our example above we wrote aes(x = gdpPercap, y = lifeExp) to tell R that gdpPercap gives the x-axis location of each point, and lifeExp gives the y-axis location. For this kind of plot, the minimum information we need to provide is the location of each point. Thus far we've only examined geom_point() which produces a scatterplot. The information we need to put in place of depends on what kind of plot we're making. This is just a fancy way of saying that it tells R how we want our plot to look. The abbreviation aes is short for aesthetic and the code mapping = aes() defines what is called an aesthetic mapping. For now, I want to focus on the somewhat more complicated-looking mapping = aes(). This will automatically add a regression line for y x to the plot. We'll see more examples in later lessons. So far we've only seen one example: geom_point() which tells ggplot that we want to make a scatterplot. The second part is also fairly straightforward: we replace with the name of a function that specifies the kind of plot we want to make. The first part is easy: we replace with the dataset we want to plot, for example gapminder_2007 in the example from above. Replacing, , and to specify what we want to plot and how it should appear.
0 Comments
Leave a Reply. |