# [R] need help with a time series plotting problem

Mon Dec 26 03:06:43 CET 2011

```vibhava wrote
>
> Dear R Users,
>                      I am a beginner in R programming and need some help
> with a simple plotting problem that i am having. My dataset consist of
> three columns: first one has data_id, second is the date and third is the
> actual data itself corresponding to each date. The date ranges from
> 1/1/2000-12/31/2009. I am trying to plot my data versus the dates as a
> long term time series but what's happening is that R is plotting each year
> on top of the previous year. so instead of getting 1 line (dated
> 2000-2009) in the plot i am getting 9 lines (1 line for each year). i
> tried to look for solutions online but found nothing. can someone suggest
> how can i make a plot with x-axis ranging from 2000-2009. my code is
> copied below:
>
> setwd("J:/Rstuff/flow")
> plot(flow\$usgs1500~as.Date(flow\$date,
> "%m/%d/%y"),type="l",xlab="date",ylab="daily discharge (m3/s)
> ",main="USGS1500",yaxs="i", xaxs="i",)
>
>
> any help would be appreciated
>
> regards
>
> vibhava
>

Hello,

If I'm understanding it well, this is a time series problem, use time series
functions.

You can use 'stats::ts' or, what seems to be better for your problem,
package zoo.
Here is an example.

library(zoo)

flow <- read.delim( ... etc ...

flow\$Date <- as.Date(flow\$Date, format="%m/%d/%Y")
head(flow\$Date)  # see if it worked

zflow <- zoo(flow[,-1], order.by=flow\$Date)  # make the time series

plot(zflow)                      # all 8 series, ugly axes
plot(zflow\$USGS700)  # just the first series, ugly axes

If this helps, then make it pretty with Jim's ideas.
See also the 'plot.zoo' help page, it has several examples with fancy
labels.