[R] plot axis appearance problem

Marc Schwartz MSchwartz at MedAnalytics.com
Fri Apr 1 21:31:24 CEST 2005


On Fri, 2005-04-01 at 18:13 +0200, Yogesh K. Tiwari wrote:
> Hello,
> 
> When I plot any data with simple plot command in 
> R, for example :-
> 
> plot(time,co2,ylim=c(350,380),xlim=c(1993,2003),xlab=NA,ylab=NA,type="p",col=5)
> 
> Then the first value of x-axis(350) and 
> y-axis(1993) never starts from origin, always they 
> sifted from the origin. Is there any command that 
> I can correct this in the ploted figure and both 
> the axis values start from origin.
> 
> Thanks for help,
> 
> Regards,
> Yogesh


If I understand you correctly, you need to specify the axis "style".

By default, R expands the axis ranges by 4% in both directions. This is
defined by par("xaxs") and par("yaxs"), where both are set to "r".  You
need to set both to "i".

Thus:

plot(time, co2, ylim = c(350, 380),
     xlim = c(1993, 2003), xlab = NA,
     ylab = NA, type = "p", col = 5
     xaxs = "i", yaxs = "i")

That will set the axis ranges to exactly your specified limits.

This is all covered in ?par

HTH,

Marc Schwartz




More information about the R-help mailing list