2016-07-25 73 views
1

如何將一些註解添加到地層圖中?在地層圖外添加註釋

例如,這裏有一個從模擬Stratiplot:

library(analogue) 
data(V12.122) 
Depths <- as.numeric(rownames(V12.122)) 
names(V12.122) 

(plt <- Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR, 
        data = V12.122, 
        type = c("h","l","g"), 
        zones = 400)) 

plt 

enter image description here

我想在藍色曲線和區域矩形最右側之間的空白添加一些文字。例如,像這樣:

enter image description here

隨着A = 150,B = 600,C = 1000

回答

1

這裏有一種方法:

pacman::p_load(analogue) 
data(V12.122) 
Depths <- as.numeric(rownames(V12.122)) 
names(V12.122) 

(plt <- Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR, 
        data = V12.122, 
        type = c("h","l","g"), 
        zones = 400)) 

(plt2 <- Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR, 
        data = V12.122, 
        type = c("h","l","g"), 
        yticks = c(150,600,1000) 
        )) 

我們需要更新的y軸像這樣的標籤:

plt2$y.scales$labels <- c("A", "B", "C") 

然後我們可以用兩個y軸繪製它,如下所示:

require(latticeExtra) 
doubleYScale(plt,plt2,add.axis=T) 

enter image description here

我檢查了這個功能的源代碼,並想通了,這是一個包裝周圍xyplot然後我做了搜索,找出doubleYScale可以採用這種方式來增加一個第二Y軸到xyscale

或者保持顏色均勻的黑色,

doubleYScale(plt,plt2,add.axis=T,use.style = F) 
+0

非常整潔,非常感謝!我將添加更新(trellis.last.object(),par.settings = simpleTheme(col = c(「black」,「black」)))'以保持顏色更統一。 – Ben