第三個解決方案是創建函數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