[R] Time Series in R with ggplot2
info at mathewanalytics.com
info at mathewanalytics.com
Fri Feb 11 23:29:03 CET 2011
Hi Folks,
First, the important information.
> sessionInfo()
R version 2.12.1 (2010-12-16)
Platform: i386-pc-mingw32/i386 (32-bit)
Second, my problem.
I have a series of data sets comprised in the following format.
> totsoc
Location Year Value
1 SOUTH 1998 29
2 SOUTH 1999 20
3 SOUTH 2000 32
4 SOUTH 2001 29
5 SOUTH 2002 25
6 SOUTH 2003 28
7 SOUTH 2004 27
8 SOUTH 2005 28
9 SOUTH 2006 22
10 SOUTH 2007 31
In order to generate a time series plot in ggplot2, I ran the following
code.
qplot(Year, Value, data=totsoc, geom="line")
ggplot(totsoc, aes(x=Year, y=Value)) + geom_line()
However, neither command acctually produces a plot with lines connecting
the
data points. I get a blank window with the general gray background and the
x
and y axis. The strange thing is that ggplot2 gives me the appropriate
output
when I use "bar" or "point". For example, these commands work.
ggplot(totsoc, aes(Year, Value)) + geom_point()
qplot(Year, Value, data=totsoc, geom="point")
I also tried to generate some sample data, and that worked. However,
I'm not sure why these same commands aren't working on the earlier data
set.
Here is the sample data I was working with.
df <- data.frame(one=c(3,8,5,4,2), two=c("KS","MO","KS","CA","IA"),
three=c(2001:2005))
qplot(three, one, data=df, geom="line")
Can anyone please help?
Thank You,
A. Mathew
More information about the R-help
mailing list