[R] no x label using axis.Date

MacQueen, Don macqueen1 at llnl.gov
Fri Jun 13 19:03:35 CEST 2014


I'd suggest a different strategy for calculating your axis. You may also
be using the axis.Date() function incorrectly. See this example:

tmpd <- data.frame(dt=seq.Date( as.Date('2014-1-7'),
as.Date('2014-08-13'), len=15),
                   y=runif(15)
                   )
xax <- seq.Date(min(tmpd$dt), max(tmpd$dt), by='mon')

plot(tmpd$dt, tmpd$y, xaxt='n')axis(1, at=xax, lab=format(xax,'%b-%Y'))


By the way, most of the information in your post does not appear to be
relevant to your question (all the stuff starting with and following the
first par() statement), and it is distracting. It's always best to pare
things down to the minimum, as it makes it easier for potential helpers.
Also, it's hard to figure out why your attempt doesn't work, because you
haven't provided a reproducible example, which is easily done.

-Don


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 6/12/14 7:47 PM, "MKN" <matthewnewland at gauge.com.au> wrote:

>I have tried multiple different methods to figure out how to get a date
>axis
>of my preference (start date of each month). Any assistance would be
>appreciated.
>The below section is not producing a date axis:
>
>plot(totaldays$totaldays,totaldays$y,type="n",ylim=c(0,Emax),xaxt="n")
>*xlabels<-(strptime(totaldays$totaldays,"%Y-%m-%d",tz=""))
>xlabels<-xlabels[xlabels$mday==1]
>axis.Date(1,at=xlabels,format="%b-%Y")*
>
>The above section is used in the following plot:
>
>par(mfrow=c(4,1))
>par(mar=c(0.8,0,0,0))
>par(oma=c(2,4.5,3,2))
>
>plot(totaldays$totaldays,totaldays$y,type="n",ylim=c(0,Dmax),xaxt="n")
>points(D$date,D$TSP,col=Dcol,type="p",pch=16,lwd=2,xaxt="n")
>text(mdate,Dmax-20,labels="DM1'",cex=1)
>legend("topright",pch=16,cex=0.8,col=colLegend,
>       legend=ALegend)
>abline(h=Target,col="red",lwd=2)
>
>plot(totaldays$totaldays,totaldays$y,type="n",ylim=c(0,Bmax),xaxt="n")
>points(B$date,B$TSP,col=Bcol,type="p",pch=16,lwd=2,xaxt="n")
>text(mdate,Bmax-20,labels="DM2",cex=1)
>abline(h=Target,col="red",lwd=2)
>
>plot(totaldays$totaldays,totaldays$y,type="n",ylim=c(0,Amax),xaxt="n")
>points(A$date,A$TSP,col=Acol,type="p",pch=16,lwd=2,xaxt="n")
>text(mdate,Amax-20,labels="DM3",cex=1)
>abline(h=Target,col="red",lwd=2)
>
>plot(totaldays$totaldays,totaldays$y,type="n",ylim=c(0,Emax),xaxt="n")
>*xlabels<-(strptime(totaldays$totaldays,"%Y-%m-%d",tz=""))
>xlabels<-xlabels[xlabels$mday==1]
>axis.Date(1,at=xlabels,format="%b-%Y")*
>points(E$date,E$TSP,col=Ecol,type="p",pch=16,lwd=2)
>text(mdate,Emax-20,labels="DM4'",cex=1)
>abline(h=Target,col="red",lwd=2)
>
>title(main=Amain, ylab=Labely,
>      outer=TRUE,cex.lab=1, cex.main=1.5)
>
>Below is an excerpt of the total days data:
>
>	totaldays	        y
>1	2013-11-01	1
>2	2013-11-02	1
>3	2013-11-03	1
>4	2013-11-04	1
>5	2013-11-05	1
>6	2013-11-06	1
>7	2013-11-07	1
>8	2013-11-08	1
>9	2013-11-09	1
>10	2013-11-10	1
>
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/no-x-label-using-axis-Date-tp4692034.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.



More information about the R-help mailing list