簡體   English   中英

使用 coplot 調整繪圖邊距

[英]Adjust plot margin with coplot

使用coplot添加標題時如何更改繪圖區域的上邊距? 更改par值似乎沒有效果。 我想增加上邊距以在那里放置標題,但更改par(mar)並沒有像我預期的那樣工作。 這是一個例子,

opar <- par(mar=c(5.1, 4.1, 20, 1))
coplot(Sepal.Length ~ Sepal.Width | Species, data=iris, columns=3,
  bar.bg=c(fac="light green"), panel=panel.smooth)   # mar=c(5.1, 4.1, 10, 1)
title("test", outer=TRUE)
par(opar)

在此處輸入圖片說明

您可以稍微向下移動它,使其不會“脫離邊緣”:

opar <- par(mar=c(5.1, 4.1, 20, 1))
coplot(Sepal.Length ~ Sepal.Width | Species, data=iris, columns=3,
  bar.bg=c(fac="light green"), panel=panel.smooth)   # mar=c(5.1, 4.1, 10, 1)
title("test", line =-1, outer=TRUE)
par(opar)

使用par()影響頂部邊距空間的努力失敗了,我懷疑這是硬編碼邊距的繪圖方法之一。 事實上,這是coplot中的代碼:

 mar <- if (have.b) 
        rep.int(0, 4)
    else c(0.5, 0, 0.5, 0)
    oma <- c(5, 6, 5, 4)
    if (have.b) {
        oma[2L] <- 5
        if (!b.is.fac) 
            oma[4L] <- 5
    }
    if (a.is.fac && show.given[1L]) 
        oma[3L] <- oma[3L] - 1

 opar <- par(mfrow = c(total.rows, total.columns), oma = oma, 
        mar = mar, xaxs = "r", yaxs = "r")

正如@42 提到的,看起來coplot的代碼包含mar的硬編碼值: https : //github.com/wch/r-source/blob/bfe73ecd848198cb9b68427cec7e70c40f96bd72/src/library/graphics/R/coplot.R#L214

另一種解決方案是將 coplot 代碼復制/粘貼到您自己的腳本中並更改函數中mar的值,但如果@42 的解決方案為您完成了這項工作,這似乎有點過分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM