Session Ready
Exercise

Log scales in economic data

Logarithmic scales are often useful for economic metrics which tend to show exponential growth over time. In this exercise we will create a dot plot of the WorldPhones dataset available in R.

In the video, you learned how to log-transform the axis by specifying a suitable base as the log component of scales. There is one more component you need to know, equispaced.log. This component indicates if the tick marks are equispaced when log scales are in use. By default, equispaced.log is set to TRUE. Note: If you set equispaced.log = FALSE, you don't have to explicitly specify a base for the log component; just log = TRUE should do the trick!

The dataset is stored as a matrix, not a data frame as expected by lattice, so we first need to transform it. Base R lets you create a tidy data frame from a matrix by converting it to a table first. That is, you use as.table() followed by as.data.frame().

Instructions
100 XP

The WorldPhones matrix is already provided, with the first row removed so you only need consider consecutive years. Using this data:

  • Transform the WorldPhones matrix into a WorldPhonesDF tidy data frame, via a table.

  • Create a dot plot conditioned on Region with Year on the y-axis and Phones on the x-axis.

  • Log-transform the x-axis.

  • Specify relation = "sliced" so that each panel has different axis limits but with a common range.