Hi, I have the following data in two columns. The first column is the date, the second is data. Date Data 3-Jan-95 459.21 4-Jan-95 459.13 5-Jan-95 460.73 6-Jan-95 460.38 9-Jan-95 460.67 10-Jan-95 460.9 11-Jan-95 461.68 12-Jan-95 461.64 13-Jan-95 461.64 16-Jan-95 465.97 17-Jan-95 469.38 18-Jan-95 470.05 19-Jan-95 469.72 20-Jan-95 466.95 23-Jan-95 464.78 24-Jan-95 465.81 25-Jan-95 465.86 I would like to used the date as the x-axis and data the y-axis. I tried plot(Data~Date,data=d), where d is the R data frame variable that holds the two columns. But something very strange happened, although the graph has dates on the x-axis, the order of these dates are wrong. I searched the help file, and realized that I need to tell R explicitly to set the date as x-axis. Unfortunately, this is as far as I got, and I couldn't figure out exactly how to do this. Could someone please provide me with an example? Thanks, Tom [[alternative HTML version deleted]]
Make sure that the Date column is actually of class "Date": DF$Date <- as.Date(DF$Date, "%d-%b-%y") plot(DF) See ?as.Date . Also read the Help Desk article in R News 4/1 to learn more about dates. On 10/18/06, tom soyer <tom.soyer at gmail.com> wrote:> Hi, > > I have the following data in two columns. The first column is the date, the > second is data. > > Date Data > 3-Jan-95 459.21 > 4-Jan-95 459.13 > 5-Jan-95 460.73 > 6-Jan-95 460.38 > 9-Jan-95 460.67 > 10-Jan-95 460.9 > 11-Jan-95 461.68 > 12-Jan-95 461.64 > 13-Jan-95 461.64 > 16-Jan-95 465.97 > 17-Jan-95 469.38 > 18-Jan-95 470.05 > 19-Jan-95 469.72 > 20-Jan-95 466.95 > 23-Jan-95 464.78 > 24-Jan-95 465.81 > 25-Jan-95 465.86 > > I would like to used the date as the x-axis and data the y-axis. I tried > plot(Data~Date,data=d), where d is the R data frame variable that holds the > two columns. But something very strange happened, although the graph has > dates on the x-axis, the order of these dates are wrong. I searched the help > file, and realized that I need to tell R explicitly to set the date as > x-axis. Unfortunately, this is as far as I got, and I couldn't figure out > exactly how to do this. Could someone please provide me with an example? > > Thanks, > > Tom > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Gabor, Thanks very much for the example. I got it to work! Tom On 10/18/06, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:> > Make sure that the Date column is actually of class "Date": > > DF$Date <- as.Date(DF$Date, "%d-%b-%y") > plot(DF) > > See ?as.Date . Also read the Help Desk article in R News 4/1 to > learn more about dates. > > On 10/18/06, tom soyer <tom.soyer@gmail.com> wrote: > > Hi, > > > > I have the following data in two columns. The first column is the date, > the > > second is data. > > > > Date Data > > 3-Jan-95 459.21 > > 4-Jan-95 459.13 > > 5-Jan-95 460.73 > > 6-Jan-95 460.38 > > 9-Jan-95 460.67 > > 10-Jan-95 460.9 > > 11-Jan-95 461.68 > > 12-Jan-95 461.64 > > 13-Jan-95 461.64 > > 16-Jan-95 465.97 > > 17-Jan-95 469.38 > > 18-Jan-95 470.05 > > 19-Jan-95 469.72 > > 20-Jan-95 466.95 > > 23-Jan-95 464.78 > > 24-Jan-95 465.81 > > 25-Jan-95 465.86 > > > > I would like to used the date as the x-axis and data the y-axis. I tried > > plot(Data~Date,data=d), where d is the R data frame variable that holds > the > > two columns. But something very strange happened, although the graph has > > dates on the x-axis, the order of these dates are wrong. I searched the > help > > file, and realized that I need to tell R explicitly to set the date as > > x-axis. Unfortunately, this is as far as I got, and I couldn't figure > out > > exactly how to do this. Could someone please provide me with an example? > > > > Thanks, > > > > Tom > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@stat.math.ethz.ch 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. > > >[[alternative HTML version deleted]]
Reasonably Related Threads
- Is there something wrong with R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"?
- Which gls models to use?
- function to generate weights for lm?
- stack charts right on top of each other
- how do I find the row index number, or row name, of a given value in a vector?