2016-08-02 91 views
1

我已經從2079至15年創建的表示溫度沉澱(右列)的變化(左列)和改變以下情節用於每個4個季節(每行):對齊尷尬情節和軸標題

enter image description here

我現在希望爲曲線左側的4個曲線圖添加一個共同的y軸標籤,名爲「Temperatures(°C)」,並且在曲線右側相同的名爲「Precipitation(mm )」。我也希望爲每一排有季節名稱的地塊設置一箇中心對齊的標題。輸出應該是這樣的:

enter image description here

我已經看過隱形地塊密謀建立座標軸標題等的各種例子,但是無法適應任何這對我的情況。任何建議非常感謝。

+0

能否請您發佈您的代碼? – Eugen

+0

對不起@ZheyuanLi,我正在度假,直到現在還沒有檢查過。這工作很好,是一個奇妙的幫助 - 謝謝! –

回答

1

正如我在5小時前的評論中所說的,有一種方法可以通過使用mtext()來解決所有定位問題;只是我不知道這是否是最好的解決方案。然而,已經有5個小時,沒有答案到達,所以我決定發佈我的。

放置「溫度」,「降水」和「冬天」沒有任何困難,但它需要一些調整放置「春天」,「夏天」和「秋天」。變量offset在以下模板代碼控制這種調整。 offset = -14.5是接近最優的,當我產生對人物:

jpeg(file = "template.jpeg", width = 600, height = 600, quality = 100) 
## template code 
dev.off() 

根據您的地塊大小,你需要調整/你需要重置offset


模板代碼

## set plot layout, inner margin and outer margin 
par(mfrow=c(4,2), mar = c(1.5,2.5,1.5,2.5), oma = c(3,4,3,4)) 

## plot 1 
plot(1:5, ann = FALSE, xaxt = "n") 
axis(4, at = axTicks(4)) 
axis(1, at = axTicks(1), labels= NA) 

## plot 2 
plot(1:5, ann = FALSE, xaxt = "n") 
axis(4, at = axTicks(4)) 
axis(1, at = axTicks(1), labels= NA) 

## plot 3 
plot(1:5, ann = FALSE, xaxt = "n") 
axis(4, at = axTicks(4)) 
axis(1, at = axTicks(1), labels= NA) 

## plot 4 
plot(1:5, ann = FALSE, xaxt = "n") 
axis(4, at = axTicks(4)) 
axis(1, at = axTicks(1), labels= NA) 

## plot 5 
plot(1:5, ann = FALSE, xaxt = "n") 
axis(4, at = axTicks(4)) 
axis(1, at = axTicks(1), labels= NA) 

## plot 6 
plot(1:5, ann = FALSE, xaxt = "n") 
axis(4, at = axTicks(4)) 
axis(1, at = axTicks(1), labels= NA) 

## plot 7 
plot(1:5, ann = FALSE) 
axis(4, at = axTicks(4)) 

## plot 8 
plot(1:5, ann = FALSE) 
axis(4, at = axTicks(4)) 

## write text on outer margins 
mtext("Temperatures (°C)", 2, outer = TRUE, line = 2, font = 2) 
mtext("Precipitation (mm)", 4, outer = TRUE, line = 2, font = 2) 
mtext("Winter", 3, outer = TRUE, line = 0, font = 2) 

## needs tuning on `offset` 
offset <- -14.5 
mtext("Spring", 3, outer = TRUE, line = offset, font = 2) 
mtext("Summer", 3, outer = TRUE, line = 2 * offset, font = 2) 
mtext("Autumn", 3, outer = TRUE, line = 3 * offset, font = 2) 

enter image description here