第三个解决方案是创建函数taylor.diagram
包括文本标签的修改后的版本。在这种情况下,所有要做的就是添加一个参数,例如text
,并且在原始函数(右花括号之前的两行)中调用points
之后,行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")
我希望能够绘制他们没有他们的位置 – Abe 2013-03-01 00:07:40
@Abe的文档的预先了解'taylor.diagram'表示它不返回点的位置(或者根本没有任何绘图信息),所以我不认为你在这里有很多选择。 – joran 2013-03-01 00:57:08