2016-03-09 42 views
0

使用coplot添加標題時,如何更改繪圖區域的上邊距?更改par值似乎沒有效果。我想增加上邊距來放置標題,但更改par(mar)未按預期工作。下面是一個例子,使用coplot調整繪圖邊距

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) 

enter image description here

+1

使用'lattice','latticeExtra',你有更多的靈活性。開始:'xyplot(Sepal.Length〜Sepal.Width | Species,data = iris,type = c(「p」,「smooth」),layout = c(3,1),main =「Test」)' –

回答

1

可以稍微下移,以便它不是「脫力」:

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