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")
flow=read.delim("flow.dat",header=TRUE,sep="\t")
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
--
View this message in context:
http://r.789695.n4.nabble.com/need-help-with-a-time-series-plotting-problem-tp4230672p4230672.html
Sent from the R help mailing list archive at Nabble.com.
you need to supply a subset of your data since the problem is probably related to its representation. please follow the posting guidelines. Sent from my iPad On Dec 24, 2011, at 2:21, vibhava <vibhavasrivastava at gmail.com> 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") > flow=read.delim("flow.dat",header=TRUE,sep="\t") > 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 > > -- > View this message in context: http://r.789695.n4.nabble.com/need-help-with-a-time-series-plotting-problem-tp4230672p4230672.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
thanks for the reply. here is subset of the data that i want to plot:
date usgs700
1 10/1/2000 0.050970325
2 10/2/2000 0.041059428
3 10/3/2000 0.032564374
4 10/4/2000 0.02775051
.
.
.
.
.
4014 9/27/2011 0
4015 9/28/2011 0
4016 9/29/2011 0
4017 9/30/2011 0
my script again is:
setwd("J:/Rstuff/flow")
flow=read.delim("flow.dat",header=TRUE,sep="\t")
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",)
i wish to plot all this data as a single time series but my program is doing
some weird stuff and the x-axis has labels Jan-dec and the long term series
is broken and plotted on yearly basis.
regards
vibhava
--
View this message in context:
http://r.789695.n4.nabble.com/need-help-with-a-time-series-plotting-problem-tp4230672p4231285.html
Sent from the R help mailing list archive at Nabble.com.
thanks for your reply. i don't think your solution is what i am looking for.
Please look at the attached two plots; first plot is what i have made using
excel and the second plot is what i was getting when i was running my script
through R yesterday night. I think my script was reading and implementing
things nicely but the only problem was that at the end of each year my time
series line use to start from the same axis label (instead of keep creating
more labels and extending the x-axis.
therefore what happened was that unlike the excel plot
which has x-axis from oct00-oct2011, i have x-axis labels jan-nov. i am
looking for something similar to excel where you select the axis and right
click on it and you can extend the x-axis.
so to sum up i *just need* to know how to extend my
x-axis (see attached figures) so that i get a continuous line (i need one
line for each plot representing 11 years of record AND DO NOT want 11 lines
representing the same thing).
regards
vibhava
http://r.789695.n4.nabble.com/file/n4232160/flow.docx flow.docx
--
View this message in context:
http://r.789695.n4.nabble.com/need-help-with-a-time-series-plotting-problem-tp4230672p4232160.html
Sent from the R help mailing list archive at Nabble.com.
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") > flow=read.delim("flow.dat",header=TRUE,sep="\t") > 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. Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/need-help-with-a-time-series-plotting-problem-tp4230672p4233688.html Sent from the R help mailing list archive at Nabble.com.
Dear Jim and Rui,
Thanks for your suggestions. i just
successfully prepared my first graph :). now i will move on to more
interesting figures. thank you once again for your help and time.
regards
vibhava
--
View this message in context:
http://r.789695.n4.nabble.com/need-help-with-a-time-series-plotting-problem-tp4230672p4245022.html
Sent from the R help mailing list archive at Nabble.com.