Log scales

1. Log scales

In the previous lesson, you created

2. Scatter plot

this scatter plot comparing the GDP per capita of each country to its life expectancy. This plot communicates some interesting information: we can see that higher income countries tend to have higher life expectancy. One problem with this plot, however, is that a lot of countries get crammed into the leftmost part of the x-axis. This is because the distribution of GDP per capita spans several orders of magnitude, with some countries in the tens of thousands of dollars and others in the hundreds. When one of your axes has that kind of distribution, it's useful to work with a logarithmic

3. Log scale

scale - that is, a scale where each fixed distance represents a multiplication of the value. This is what the scatter plot looks like when x is on a log scale. This is the same data, but now each unit on the x-axis represents a change of 10 times the GDP. You can see the axis goes from one thousand to ten thousand, and the next step of an equal distance would be one hundred thousand. On this scale, the relationship between GDP per capita and life expectancy looks more linear: and you can more easily distinguish the countries at the lower end of the spectrum. To create this graph, you would add one additional option to our ggplot call, with another "plus" after geom_point. You would add scale underscore x underscore log10. This is how you specify that we want the x axis on a log10 scale. It's not necessary in this case, but if you wanted to put the y-axis on a log scale as well, you would use scale underscore y underscore log10.

4. Let's practice!

You'll practice putting the x- and y- axes on a log scale in the exercises. Many of the graphs you'll make in this course will need at least one of the axes to be logarithmic.