Line plots
1. Line plots
The graphs you've made so far in this course have all been2. Life Expectancy vs GDP
scatter plots, like this one. These are useful for comparing two variables, such as GDP per capita and life expectancy, with each point representing one observation. But there are many other types of graphs you can make with ggplot2, each of which is useful for visualizing a particular type of data. In3. Types of plots
this chapter, you'll learn to make four more types of graphs. You'll make line plots, which are useful for showing change over time. You'll create bar plots, which are good at comparing statistics for each of several categories. You'll learn to make histograms, which describe the distribution of a one-dimensional numeric variable. And you'll make box plots, which compare the distribution of a numeric variable among several categories. You'll see how the R code to create each is similar to a scatter plot, where you map variables in your data, like life expectancy and GDP, to visual aesthetics, such as x and y. Once you master this approach, you'll be able to visualize your data in many ways besides the ones taught in this course.4. Scatter vs line plot
You'll start by making a line plot, for visualizing a change over time. In the last chapter, you created a plot like this to show the mean life expectancy in each continent in each year. You can get a sense of the trends from this plot. But it's a bit easier to understand as a line plot, where the observations within each continent are connected. This makes it clearer that what we care about is the upward or downward trend over time. The way you make a line plot is to change one part of the code. geom_point was the part of the code that specified you were making a scatter plot. Simply change that to geom_line to make a line plot. So this is5. Line plot
how you make a line plot. Most of it looks exactly the same as a scatter plot: provide the data you're plotting, the aesthetics of x, y, and color, and end with expand_limits(y = 0). The only difference is the type of plot: geom underscore line. In the exercises, you'll use code like this to generate several visualizations of change over time.6. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.