Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing all margins in an R graphics device

Tags:

r

So I'm having a bit of trouble getting rid of the entire margin of a graphics device. I've set mar to 0, but there is still some persistent space around the edge. For example:

plot.new()
par(mar=c(0,0,0,0))
plot.window(c(0,1),c(0,1))
points(c(1,1,0,0),c(1,0,1,0))

enter image description here

I would like the points to be centered at the extreme edges of the plot. Is there a par that I am missing?

like image 227
Ian Fellows Avatar asked Jun 17 '11 00:06

Ian Fellows


1 Answers

This is controlled by the arguments to ?par xaxs and yaxs. These are passed on by the ... argument of plot.window and other plot functions.

plot.window(c(0,1),c(0,1), xaxs = "i", yaxs = "i")

From the help page for ?par, the default setting "r" extends the data range by 4 percent, and "i" uses the data range exactly:

Style ‘"r"’ (regular) first extends the data range by 4 percent at each end and then finds an axis with pretty labels that fits within the extended range. Style ‘"i"’ (internal) just finds an axis with pretty labels that fits within the original data range.

like image 132
mdsumner Avatar answered Oct 12 '22 16:10

mdsumner