Please keep the mailing list included. I don't provide help offline.
The Posting Guide (mentioned at the bottom of every message on this list)
requests that you provide a small reproducible example. Your example is
not yet reproducible. Reading files off your disk is generally not an
option in a reproducible example. You may find [1] helpful in clarifying
the meaning of reproducibility. Pay particular attention to the use of
"dput" which can let us tell exactly what is in the objects you have
read
in. Just because a column "looks" like a Date doesn't mean it is a
Date.
I see you have toyed around with the as.Date function, but I don't see
that you have applied it to the data you read in. Something like
LPB_PPT_R$Date <- as.Date( as.character( LPB_PPT_R$Date ) )
might help.
I also don't see that you have made a ts object out of the information in
that data frame, so plot.ts may behave oddly with the information you are
giving it. I don't use ts myself, but reading ?as.ts it doesn't seem to
have an option to give specified timestamps. If you know you will need
timeseries analysis, you might consider the xts package which does accept
specified timestamps.
Note that once you have converted the Date column to a Date type, you can
probably plot the data without the ts object that plot.ts wants... just
plot( Rain_cm + Cum_PPT ~ Date, data=LPB_PPT_R )
On Sun, 3 May 2015, Dot Lundberg wrote:
>
> ---------- Forwarded message ----------
> From: Dot Lundberg <dotlundberg at gmail.com>
> Date: Sun, May 3, 2015 at 7:31 PM
> Subject: Re: [R] (no subject)
> To: Jim Lemon <drjimlemon at gmail.com>
> Cc: r-help at r-project.org
>
>
> Hello,
>
> Here is the example of the dataset and code I am working with.? I have also
attached a photo of the
> graphs it produces.? I am trying to get the x axis to read the dates as
dates not a count of the dates.
>
> getwd()
> [1] "C:/Users/Dot/Documents"
> > setwd("c:/users/dot/desktop/r")
> > list.files()
> ?[1] "DEAL4_2_43531.csv"?? "DitchR"?????????????
"karen_question.pptx"
> ?[4] "LPB_PPT_R.csv"?????? "LPB_R.csv"??????????
"LPB_R.xlsx"????????
> ?[7] "R codes.docx"??????? "Seasons_D4.csv"?????
"test.R"????????????
> [10] "YearData.csv"??????
> > DEAL4_2_43531<-read.csv("DEAL4_2_43531.csv")
> > LPB_PPT_R<-read.csv("LPB_PPT_R.csv")
> > LPB_PPT_R<-read.csv("LPB_PPT_R.csv", header=TRUE)
> > attach(LPB_PPT_R)
> > names(LPB_PPT_R)
> [1] "Date"??? "Rain_cm" "Cum_PPT"
> > class(LPB_PPT_R)
> [1] "data.frame"
> > as.Date(40007, origin = "1900-01-01")
> [1] "2009-07-15"
> ?plot.ts(LPB_PPT_R[,2:3], type="l", col="black",
xlab="Date")
> >? head(LPB_PPT_R)
> ??????? Date Rain_cm Cum_PPT
> 1 2009-07-15? 0.0254??? 0.03
> 2 2009-07-16? 0.0000??? 0.03
> 3 2009-07-17? 0.0000??? 0.03
> 4 2009-07-18? 0.0000??? 0.03
> 5 2009-07-19? 0.0000??? 0.03
> 6 2009-07-20? 0.0000??? 0.03
> >
>
>
> Any help would be greatly appreciated. Thanks!
>
>
>
>
> On Wed, Apr 15, 2015 at 5:02 AM, Jim Lemon <drjimlemon at gmail.com>
wrote:
> Hi Dot,
> Jeff's guess is probably correct, but perhaps you could describe
the
> crazy tick marks and the repeating labels a little more. I suspect
> that if "newdate" was a character variable you wouldn't
get a plot at
> all, and if it is a factor, a few of the labels might identify what
> went wrong.
>
> Jim
>
> > On April 14, 2015 5:04:48 PM PDT, Dot Lundberg <dotlundberg
at gmail.com>
> > wrote:
> >>New to R. Having trouble with the xaxis in this code. The
tick marks
> >>are
> >>crazy and the labels repeat. Any suggestions?
> >>
> >>par(mar=c(5,5,5,5))
> >>
>
>>plot(LPB_PPT_R$newdate,LPB_PPT_R$Rain_cm,pch=0,type="l",col="black",yaxt="n",ylim=c(0,8),ylab="")
> >>axis(side=2, at=c(0,2,4,6,8))
> >>mtext("Precipitation (cm)", side = 2, line=2.5,
at=4)
> >>mtext("Date", side=1, line=2.5)
> >>axis.Date(1, at=seq(min(LPB_PPT_R$newdate),
> >>max(LPB_PPT_R$newdate),las=2,by="1
weeks"),format="%m-%Y")
> >>
> >>par(new=TRUE)
> >>
>
>>plot(LPB_PPT_R$newdate,LPB_PPT_R$Cum_PPT,pch=1,type="l",col="grey",yaxt="n",ylim=c(0,100),
> >>ylab="")
> >>axis(side=4, at=c(0,50,100))
> >>mtext("Cumulative Precipitation (cm)", side=4,
line=2.5, at=50,
> >>col="grey")
> >>
> >>? ? ? [[alternative HTML version deleted]]
> >>
> >>______________________________________________
> >>R-help at r-project.org mailing list -- To UNSUBSCRIBE and
more, see
> >>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.
>
>
>
>
>
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------