1. Learn
  2. /
  3. Courses
  4. /
  5. Working with Dates and Times in R

Exercise

Plotting

If you plot a Date on the axis of a plot, you expect the dates to be in calendar order, and that's exactly what happens with plot() or ggplot().

In this exercise you'll make some plots with the R version releases data from the previous exercises using ggplot2. There are two big differences when a Date is on an axis:

  1. If you specify limits they must be Date objects.

  2. To control the behavior of the scale you use the scale_x_date() function.

Have a go in this exercise where you explore how often R releases occur.

Instructions

100 XP
  • Make a plot of releases over time by setting the x argument of the aes() function to the date column.
  • Zoom in to the period from 2010 to 2014 by specifying limits from "2010-01-01" to "2014-01-01". Notice these strings need to be wrapped in as.Date() to be interpreted as Date objects.
  • Adjust the axis labeling by specifying date_breaks of "10 years" and date_labels of "%Y".