第三种解决方案是创建taylor.diagram
包含文本标签的函数的修改版本。在这种情况下,所要做的就是添加一个参数,比如说text
,然后在调用points
原始函数之后(右大括号前 2 行)添加text(sd.f * R, sd.f * sin(acos(R)), labels=text, pos=3)
.
taylor.diagram.modified <- function (ref, model, add = FALSE, col = "red",
pch = 19, pos.cor = TRUE, xlab = "", ylab = "",
main = "Taylor Diagram", show.gamma = TRUE,
ngamma = 3, gamma.col = 8, sd.arcs = 0, ref.sd = FALSE,
grad.corr.lines = c(0.2, 0.4, 0.6, 0.8, 0.9), pcex = 1,
cex.axis = 1, normalize = FALSE, mar = c(5, 4, 6, 6),
text, ...) #the added parameter
{
grad.corr.full <- c(0, 0.2, 0.4, 0.6, 0.8, 0.9, 0.95, 0.99,1)
R <- cor(ref, model, use = "pairwise")
sd.r <- sd(ref)
sd.f <- sd(model)
if (normalize) {
... #I didn't copy here the full function because it's quite long: to obtain it
... #simply call `taylor.diagram` in the console or `edit(taylor.diagram)`.
}
S <- (2 * (1 + R))/(sd.f + (1/sd.f))^2
}
}
points(sd.f * R, sd.f * sin(acos(R)), pch = pch, col = col,
cex = pcex)
text(sd.f * R, sd.f * sin(acos(R)), #the line to add
labels=text, cex = pcex, pos=3) #You can change the pos argument to your liking
invisible(oldpar)
}
然后只需在参数中提供一个标签名称text
:
require(plotrix)
set.seed(10)
data <- sort(runif(100, 8,12))
model <- sort(rnorm(100, 10, 4))
taylor.diagram.modified(data, model, text="Model 1")
model2 <- sort(rnorm(100, 10,2))
taylor.diagram.modified(data, model2, add = TRUE, text="Model 2")