Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the zero tick appear in the lefthand corner in R plots?

Tags:

graph

r

When you generate plots in R with the 'plot' command, and set the left side x-axis limit to zero, with, e.g.

plot(x=c(1:10), y=c(1:10), xlim=c(0,10), ylim=c(0,10))

R, for reasons which are not apparent to me, puts a bunch of extra space between the point (0,0) and the bottom lefthand corner (also at the top).

I can get the graph I want by manually guessing the offsets, and adjusting the bottom and left axis limits accordingly:

plot(x=c(1:10), y=c(1:10), xlim=c(0.38,10), ylim=c(0.38,10))

But the problem is, I have to do this manually for each graph, which seems excessive.

Is there a par-type setting for removing this margin?

like image 769
John Doucette Avatar asked Mar 18 '12 02:03

John Doucette


1 Answers

In calls to plot(), both xlim and ylim are by default padded (extended) by 4%. To suppress this behavior, set xaxs = "i" and/or yaxs = "i".

For more details, see the help page for par.

plot(x=c(1:10), y=c(1:10), xlim=c(0,10), ylim=c(0,10), xaxs="i", yaxs="i")

enter image description here

like image 65
Josh O'Brien Avatar answered Sep 26 '22 02:09

Josh O'Brien