R 如何在泰勒图中标记点?

R 如何在泰勒图中标记点?,r,plot,R,Plot,这个包有一个名为taylor.diagram的函数,它绘制了两个向量——一个表示数据,另一个表示模型输出 以下是一个例子: require(plotrix) set.seed(10) data <- sort(runif(100, 8,12)) model <- sort(rnorm(100, 10, 4)) taylor.diagram(data, model) require(plotrix) 种子(10) 数据与使用文本在基本图形中标记所有内容的方式相同: text(1.5

这个包有一个名为
taylor.diagram
的函数,它绘制了两个向量——一个表示数据,另一个表示模型输出

以下是一个例子:

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

数据与使用
文本在基本图形中标记所有内容的方式相同:

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

这里有两种方法

  • 示例(taylor.diagram)
    展示了一种在右上角放置图例的不错方法(在
    1.5*sd(数据)和1.5*sd(数据)
    ),但这需要两个点使用不同的颜色

  • 另一种选择是根据原始公式计算位置,或者将它们从源代码复制到附近的
    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")
    

    dy第三种解决方案是创建包含文本标签的函数
    taylor.diagram
    的修改版本。在这种情况下,所要做的就是添加一个参数,比如说
    text
    ,在调用原始函数中的
    点之后(右括号前的两行),该行
    text(sd.f*R,sd.f*sin(acos(R)),labels=text,pos=3)


    我希望能够在事先不知道它们的特性的情况下绘制它们position@Abetaylor.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")
    
    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)
    }
    
    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")