我试图删除R中的绘图的所有边距和"图形区域",以便绘图区域包含整个图形设备.我认为下面的代码会这样做,但我的情节周围仍然有一个边框(左/下宽,上/右更薄).谢谢
par(oma=c(0, 0, 0, 0))
par(mar=c(0, 0, 0, 0))
par(plt=c(0, 1, 0, 1))
以为我会添加一张图片来展示我的进步.xaxs和yaxs几乎从顶部和右边移除了所有边界 - 左边和底部仍然有一个边框.

我脚本的相关部分如下.
png("Test.png", 
     width = 256, height = 256,
     units = "px", pointsize = 6.4, 
     bg = "black", res = NA)
par(mar=c(0, 0, 0, 0), xaxs='i', yaxs='i')
smoothScatter(lhb$px, lhb$pz, nrpoints=0, xlim=c(-3,3), ylim=c(0,5), 
    main="", xlab="", ylab="", axes=FALSE, 
    colramp=colorRampPalette(c("black", "#202020", "#736AFF", "cyan", "yellow", "#F87431", "#FF7F00", "red", "#7E2217"))
    )
segments(.83, 1.597, .83, 3.436, col = par("fg"), lty = par("lty"), lwd = par("lwd"))
segments(-.83, 1.597, -.83, 3.436, col = par("fg"), lty = par("lty"), lwd = par("lwd"))
segments(-.83, 3.436, .83, 3.436, col = par("fg"), lty = par("lty"), lwd = par("lwd"))
segments(-.83, 1.597, .83, 1.597, col = par("fg"), lty = par("lty"), lwd = par("lwd"))
dev.off()
Rei*_*son 15
一个问题基本上没有得到什么plt.从?par我们有:
 ‘plt’ A vector of the form ‘c(x1, x2, y1, y2)’ giving the
      coordinates of the plot region as fractions of the current
      figure region.
所以你的情节区域是零大小,如果你这样做par(plt=c(1, 1, 1, 1)),所以这似乎不是要走的路.这是因为图形区域包含绘图区域.
这个情节似乎覆盖了整个地区,没有任何边缘:
op <- par(mar = rep(0, 4))
plot(1:10)
par(op)
它覆盖得很好,你看不到轴或盒子:

假定0外边距(oma)的默认值.这是你在找什么?
我们可以看到,只需调整绘图边距,如上所述,我们也将plt参数更改为副作用:
> par("plt")
[1] 0.1173174 0.9399106 0.1457273 0.8828467
> op <- par(mar = rep(0, 4))
> par("plt")
[1] 0 1 0 1
> par(op)
> par("plt")
[1] 0.1173174 0.9399106 0.1457273 0.8828467
表示简单地设置绘图边距足以获得包含整个设备的绘图/图形区域.
当然,仍然有一些内部填充确保轴的范围略大于x和y坐标中的数据范围.但你可以控制这个xaxs和yaxs---看?par
更新:由于OP已经展示了他们试图在没有边距的情况下生成的那种图形,我可以提供一个可重现的例子:
set.seed(1)
dat <- matrix(rnorm(100*100), ncol = 100, nrow = 100)
layout(matrix(1:2, ncol = 2))
image(dat)
op <- par(mar = rep(0, 4))
image(dat)
par(op)
layout(1)
这给出了比较:

并显示完整的绘图区域:

| 归档时间: | 
 | 
| 查看次数: | 21358 次 | 
| 最近记录: |