简体   繁体   English

R:如何删除图中的微小轴边距

[英]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. 我想摆脱X和Y值(图片上的红线)接近零的小边距,并仅绘制红色方块中显示的内容。

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? 我尝试设置par(mar = rep(0, 4)xlim=c(0, ...)ylim=c(0, ...)但是R仍然不断添加这个微小的空白。如何摆脱它?

以边距在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: 我最后得到一个不在“ true” 0,0点处的圆: 圆应在0,0点上

EDIT2: Actually what I want to do, is to plot circles of different radius, and save it as an image. EDIT2:实际上我想做的是绘制不同半径的圆,并将其保存为图像。 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". 您可以将xaxsyaxs参数设置为“ i”,而不是默认的“ r”。 From the par help page: par帮助页面:

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. 样式“ r”(常规)首先在每一端将数据范围扩展4%,然后找到带有适合扩展范围的漂亮标签的轴。

Style "i" (internal) just finds an axis with pretty labels that fits within the original data range. 样式“ i”(内部)仅找到带有适合原始数据范围的漂亮标签的轴。

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: 给出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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