You can't expect R and plot()
to make up numeric values from arbitrary character strings that you as a human understand but might as well be gibberish to a computer!
You need to inform R that the vector Date
in your data frame represents a date - in R parlance an object of class "Date"
. Now as you don't have days there, we have to make them up - the first of each month will suffice. Consider this simple example data set
df <- data.frame(Date = paste(month.abb, "13", sep = "-"),
AccBH = rnorm(12))
I inform R that Date
is a "Date"
object through as.Date()
. Notice here I am pasting on 01-
to each of the month-year combinations already in df
. An appropriate format
specifier is also provided to tell R how to "read" the elements of the date (read ?strftime
for those details)
df <- transform(df,
Date = as.Date(paste("01", as.character(df$Date), sep = "-"),
format = "%d-%b-%y"))
Once we have the data in the correct format, as shown here by the str()
function
> str(df)
'data.frame': 12 obs. of 2 variables:
$ Date : Date, format: "2013-01-01" "2013-02-01" ...
$ AccBH: num 0.494 -0.759 -2.204 -2.004 2.808 ...
plot()
works appropriately:
plot(AccBH ~ Date, data = df, type = "l")
producing something like (you'll have different data):

If you want different labelling, then you'll need to specify it yourself, e.g.
plot(AccBH ~ Date, data = df, type = "l", xaxt = "n")
with(df, axis.Date(side = 1, x = Date, format = "%b-%y"))

See ?axis.Date
for more details.
Note there is the zoo package which has a data type specifically for this year-month, the "yearmon"
class. You can use this without fiddling with your original data
df2 <- data.frame(Date = paste(month.abb, "13", sep = "-"),
AccBH = rnorm(12))
through the use of the as.yearmon()
function
require("zoo")
df2 <- transform(df2, Date = as.yearmon(Date, format = "%b-%y"))
Then create a "zoo"
object using the variables thus created
zobj <- with(df2, zoo(AccBH, order.by = Date))
This gives
> zobj
Jan 2013 Feb 2013 Mar 2013 Apr 2013 May 2013 Jun 2013
-0.607986011 1.741046878 -0.603960213 -1.319397405 -0.355051912 0.296862314
Jul 2013 Aug 2013 Sep 2013 Oct 2013 Nov 2013 Dec 2013
0.235978782 -0.308123299 -0.200230379 -0.004428621 -0.858600654 -0.241808594
Which can then be plotted
plot(zobj)
but note it has it's own way of labelling the axes.
