简体   繁体   中英

R: how to remove this tiny axis margin in plot

I want to get rid the small margin close to zero on X and Y value (red line on pic), and plot ONLY what is showed in red square.

I tried setting par(mar = rep(0, 4) and xlim=c(0, ...) , ylim=c(0, ...) but R still keeps adding this tiny margin. How to get rid of it?

以边距在R中绘图

EDIT: another point of view on my problem: after running:

require(plotrix)
axisRange <- c(0,500)
plot(NULL, xlim = axisRange, ylim=axisRange)
draw.circle(0, 0, 200, col = "white", border = "red")

I end up with a circle positioned not in "true" 0,0 point: 圆应在0,0点上

EDIT2: Actually what I want to do, is to plot circles of different radius, and save it as an image. That is why I care about the margins. I end up with something like this (spots on the corners are for the reference):

在此处输入图片说明

And should be more like this: 在此处输入图片说明

You can set the xaxs and yaxs arguments to "i" as opposed to the default of "r". From the par help page:

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.

library(plotrix)
axisRange <- c(0,500)
par(mar = rep(0,4))
plot(NULL, xlim = axisRange, ylim=axisRange, xaxs = "i", yaxs = "i")
draw.circle(0, 0, 200, col = "white", border = "red")

Gives:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM