Visualize your data - line chart
4. Draw a line chart
Work with your chart
Check yourself

Instruction

Now we know everything necessary to plot a line chart, so let's do this in R.

The only new thing we need is one piece of code – a new geometry, geom_line(), which we will add to our standard ggplot syntax:

ggplot(data=dataset, mapping=aes(x=variable_x, y=variable_y)) + geom_line()

Exercise

Plot the data on the line chart. Use the above syntax to and make the dataset zimbabwe_consumption_2. Set consumption as y and year as x. Pass the whole command to the line object.

Stuck? Here's a hint!

You should write:

line <- ggplot(
  data = zimbabwe_consumption_2, 
  aes(x = year, y = consumption)) + 
  geom_line()