2013-02-28 96 views
3

plotrix程序包有一个叫做taylor.diagram的函数,它绘制两个向量 - 一个表示数据和另一个模型输出。如何在泰勒图中标注点?

下面是一个例子:

require(plotrix) 
set.seed(10) 
data <- sort(runif(100, 8,12)) 
model <- sort(rnorm(100, 10, 4)) 
taylor.diagram(data, model) 

而在这个例子中,我想提高模型后更新的情节:

model2 <- sort(rnorm(100, 10,2)) 
taylor.diagram(data, model2, add = TRUE) 

要产生这样的:

enter image description here

如何添加“模型1”和“模型2”等标签以识别t这些点? (更新:从而不做,事后的模型值确定标签位置)

回答

0

您的标签在基地的图形都用同样的方法,用text

text(1.5,0.5,labels = "Model2") 
text(3.5,1,labels = "Model1") 

enter image description here

+0

我希望能够绘制他们没有他们的位置 – Abe 2013-03-01 00:07:40

+0

@Abe的文档的预先了解'taylor.diagram'表示它不返回点的位置(或者根本没有任何绘图信息),所以我不认为你在这里有很多选择。 – joran 2013-03-01 00:57:08

1

这里有两种方法

  1. example(taylor.diagram)显示了一个体面的方式来放置一个传说右上角(在1.5*sd(data), 1.5*sd(data)),但这需要两点不同的颜色。

  2. 另一种选择是基于从原来的Taylor 2001 reference的公式来计算位置 - 或从源代码到taylor.diagram功能复制它们,近

    dy <- 1.1 # text offset coefficient 
    sd.f <- sd(model) 
    R <- cor(data, model, use = 'pairwise') 
    x <- sd.f * R 
    y <- sd.f * sin(acos(R)) + dy * sd.f 
    text(x, y, "Model") 
    

    您需要计算这些各型号,但只有模型输入和标签会改变。你可能想保持偏移量一样。

3

第三个解决方案是创建函数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") 

enter image description here