[R] Scaling x axis

Jim Lemon drjimlemon at gmail.com
Fri Feb 26 03:24:05 CET 2016


Hi Fabio,
If you have more than a few dates on the X axis you may get
overlapping tick labels. As an example, take a plot of the winning
parties of by-elections held in Australia in the 21st century by the
dates of the elections:

be_dates<-as.Date(c("5/12/2015","19/09/2015","8/2/2014",
 "5/12/2009","6/9/2008","6/9/2008","28/6/2008","19/3/2005","19/10/2002",
 "14/7/2001","17/3/2001","12/8/2000"),"%d/%m/%Y")
be_parties<-factor(c("Lib","Lib","Lab","Lib","Ind","Lib","Nat",
 "Lab","Grn","Lib","Lab","Lab"))
par(mar=c(6,4,4,2))
plot(be_dates,be_parties,xaxt="n",yaxt="n",
 xlab="",ylab="Winning party",pch=as.numeric(be_parties))
require(plotrix)
staxlab(1,at=be_dates,labels=format(be_dates,"%d/%m/%Y"),nlines=4)
axis(2,at=1:5,labels=levels(be_parties))
mtext("By-election dates",side=1,line=4)

As you can see, most dates would overlap other dates using the standard axis.

Jim

On Thu, Feb 25, 2016 at 11:31 PM, Fabio Monteiro
<fabio.monteiro1992 at gmail.com> wrote:
> Hi
>
> i'm trying to plot my data in R and i can't manage to scale the x axis.
>
> My x axis are dates, months and years, and when I plot I only have the x
> axis like this (2002, 2004, 2006, 2008, 2010).
>
> I whant every date in the axis not only those years, i want to see every
> point with the respectively date in the axis.
>
> How can I do that?
>
> Kind regards
>
> Fábio monteiro
>
>         [[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.



More information about the R-help mailing list