O'Reilly logo

R Graph Essentials by David Alexander Lillis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating graphs with dates

Sometimes, you may wish to create a time series graph that involves dates along the horizontal axis. We can create such graphs using qplot. Let's try plotting a time series graph. We use the built-in economics dataset (see http://docs.ggplot2.org/current/economics.html) and plot the population against the date. Let's see the first six rows using head():

head(economics)

Here are the first six rows of the data:

      date    pce   pop    psavert  uempmed unemploy
1 1967-06-30 507.8 198712     9.8     4.5     2944
2 1967-07-31 510.9 198911     9.8     4.7     2945
3 1967-08-31 516.7 199113     9.0     4.6     2958
4 1967-09-30 513.3 199311     9.8     4.9     3143
5 1967-10-31 518.5 199498     9.7     4.7     3066
6 1967-11-30 526.2 199657     9.4     4.8     3018

Now we look at the last six rows using the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required