Tinniam V. Ganesh
Tinniam V. Ganesh

Reputation: 2079

How to plot the this time series data

I have the following data showing the value of a variable at different dates. How can I plot this data? The data is shown below. The b column goes up 2004.

       a          b
1     44 1990-12-06
2      5 1990-12-06
3     17 1992-04-18
4     64 1992-04-18
5     58 1992-11-27
6      0 1992-11-27
7     52 1992-12-26
8      4 1992-12-26
9    277 1993-01-02
10    52 1993-01-23
11     7 1993-01-23
...

The a & b columns are interchangeable. I would like to plot this as a performance from the start year to the end year.

Any help will be appreciated

Upvotes: 0

Views: 68

Answers (1)

Stephan Kolassa
Stephan Kolassa

Reputation: 8267

Does a simple time series plot do what you want?

foo <- structure(list(a = c(44, 5, 17, 64, 58, 0, 52, 4, 277, 52, 7), 
    b = structure(c(7644, 7644, 8143, 8143, 8366, 8366, 8395, 
    8395, 8402, 8423, 8423), class = "Date")), .Names = c("a", 
"b"), row.names = c(NA, -11L), class = "data.frame")
plot(foo$b,foo$a,type="o")

timeseries

If you have many values, I'd recommend plotting them in gray (so you don't lose your original data) and overlaying them with a smoothed curve, like this:

foo <- data.frame(a=rnorm(366),b=as.Date("2015-01-01")+(0:365))
plot(foo$b,foo$a,type="o",col="grey")
lines(foo$b,predict(loess(a~as.numeric(b),foo)),lwd=2)

timeseries with loess Incidentally, this textbook section on graphical time series tools may be helpful.

Upvotes: 4

Related Questions