【问题标题】:Changing colors of points using qqmath from the lattice package使用 lattice 包中的 qqmath 更改点的颜色
【发布时间】:2019-12-11 20:27:49
【问题描述】:

我在 Lattice 包中使用 qqmath 制作了一个绘图(我将其子集为仅 3 个点,以便于示例)。

table <- data.table(Col1=c(12,3,4), Col2 = c(54,4,6), Col3 = c("Pink", "Pink", "Red"))

PrbGrd <- qnorm(c(0.00001,0.0001,0.001,0.01, 0.05, 0.10,0.20,0.30,0.40, 
0.50, 0.60, 0.70,0.80,0.90,0.95,0.99,0.999,0.9999,0.99999))

PrbGrdL<-c("0.001","0.01","0.1","1","5","10","20","30","40","50","60","70","80","90","95","99","99.9","99.99","99.999")
PrbGrdL2<- c("99.999","99.99","99.9","99","95","90","80","70","60","50","40","30","20","10","5","1","0.1","0.01","0.001")


ValGrd<- c(seq(0.001,0.01,0.001),seq(0.01,0.1,0.01),seq(0.1,1,0.1),seq(1,10,1),seq(10,100,10),seq(100,1000,100),seq(1000,10000,1000))
ValGrd<- log10(ValGrd)
ValGrd2 <- c(-2:20)


ProbPlot <- qqmath(~ Col1, 
                data= table,
                distribution = function(p) qnorm(p),
                main = "Normal probability plot",
                pch=20,
                cex=0.5,
                xlab="Probability of Lower",
                ylab = "Pb",
                #xlim = c(max(PrbGrd),min(PrbGrd)),
                xlim = c(min(PrbGrd),max(PrbGrd)),
                scales=list(y=list(alternating=1),x = list(at = PrbGrd, labels = PrbGrdL, cex = 0.8)),
                #yscale.components=yscale.components.log10ticks,
                panel=function(x,...){
                  panel.abline(v=PrbGrd ,col="grey",lty=3)
                  panel.abline(h=ValGrd2,col="grey",lty=3)
                  panel.qqmath(x,distribution=qnorm)
                }
)

我想使用表格第三列 (Col3) 中的颜色来更改绘图上各个点的颜色。我不知道如何在 qqmath 中做到这一点,使用常规绘图功能会很简单......但使用 qqmath 似乎并不那么简单。

谢谢!

【问题讨论】:

    标签: r colors package lattice


    【解决方案1】:

    更新:基于 OP 的评论。

    您可以添加col 参数,例如:

    ProbPlot <- qqmath(~ Col1, 
                    data = table,
                    distribution = function(p) qnorm(p),
                    main = "Normal probability plot",
                    pch = 20,
                    cex = 0.5,
                    xlab = "Probability of Lower",
                    ylab = "Pb",
                    #xlim = c(max(PrbGrd),min(PrbGrd)),
                    xlim = c(min(PrbGrd),max(PrbGrd)),
                    scales = list(y = list(alternating = 1),
                                  x = list(at = PrbGrd,
                                           labels = PrbGrdL,
                                           cex = 0.8)),
                    #yscale.components=yscale.components.log10ticks,
                    panel = function(x, ...){
                      panel.abline(v = PrbGrd, 
                                   col = "grey", 
                                   lty = 3)
                      panel.abline(h = ValGrd2, 
                                   col = "grey", 
                                   lty = 3)
                      panel.qqmath(x,
                                   distribution=qnorm,
                                   col = table$Col3) # add colors for each point
                    }
    )
    

    【讨论】:

    • 啊,我注释掉了一些代码,因为它没有运行。你刚刚添加了它。我去看看我能找到什么。
    • 我更新了答案。问题出在panel 参数上。 col = table$Col3 放错地方了。
    猜你喜欢
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 2023-03-15
    相关资源
    最近更新 更多