2011-04-14 79 views
12

我试图删除所有边距和R中绘图的“图形区域”,以便绘图区域包含整个图形设备。我认为下面的代码可以做到这一点,但是我的情节仍然存在一个边界(左侧/底部较宽,顶部/右侧较薄)。谢谢试图删除所有边距,使绘图区域包含整个图形

par(oma=c(0, 0, 0, 0)) 
par(mar=c(0, 0, 0, 0)) 
par(plt=c(0, 1, 0, 1)) 

以为我会添加一张图片来显示我的进度。 xaxs和yaxs从顶部和右侧移除了几乎所有边界 - 左侧和底部仍然有一个边框。

R plot

我的剧本的相关部分如下。

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

回答

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) 

它涵盖这么好,你看不到的轴或盒子:

full region covered

这假定为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 

表明简单的设置情节利润率足以获得剧情/图包含整个设备的区域。

当然,仍然有一些内部填充确保轴的范围稍大于数据在xy坐标中的范围。但是你可以用xaxsyaxs控制这一---看到?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) 

这给出了比较:

comparison of default and no margins respectively

,并只显示完整的绘图区域:

full plot region covered

+0

感谢对PLT()校正,我发现这个在你写你的答复,同时,它改变成上述PLT(0,1,0,1)。也会研究其他建议。 – taglius 2011-04-14 13:43:57

+0

@taglius - 如果你设置'par(mar = rep(0,4))',你根本不需要它。通过设置零边距,'plt'将被设置为'c(0,1,0,1)'。在一分钟内查看我的答案的小更新。 – 2011-04-14 14:13:48

+2

这看起来是正确的,如上面我的脚本中设置par(mar = c(0,0,0,0),xaxs ='i',yaxs ='i') 完全摆脱了顶部和右侧。现在我只需要摆脱左/底 – taglius 2011-04-14 18:07:11

0

尝试设置剪辑区域参数 'XPD' 到NA(剪切为设备)。

面值(XPD = NA)

+1

感谢您的想法,这似乎没有改变任何东西 – taglius 2011-04-20 20:33:18