Remove spacing around plotting area in r

前端 未结 2 974
既然无缘
既然无缘 2020-12-13 00:28

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

2条回答
  •  余生分开走
    2020-12-13 01:29

    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"))
    

    enter image description here

提交回复
热议问题