When I create the following plot I get unwanted space between the plotting area and the axis (i.e. the white space between the blue box and the x axis. How can I remove this
plot(c(1,2.75),c(1,2.75),type="n",main="title",xlab="site.x",ylab="ylab",axes=F) # ann
axis(1,pos=1)
axis(2,pos=1)
All axes are remove then you can add new axes to the pos
you want.
There is an argument in function plot
that handles that: xaxs
(and yaxs
for the y-axis).
As default it is set to xaxs="r"
meaning that 4% of the axis value is left on each side. To set this to 0: xaxs="i"
. See the xaxs
section in ?par
for more information.
plot(c(1,2.75),c(1,2.75),type="n",main="title",xlab="site.x",ylab="ylab", xaxs="i", yaxs="i")
rect(xleft,ybottom,xright,ytop,col=c("blue","red","green"))