在地层图之外添加注释

时间:2016-07-25 02:01:03

标签: r plot lattice

如何在地层图中添加一些注释?

例如,这里有来自模拟的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 个答案:

答案 0 :(得分: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)