r - 使用 lattice 包中的 qqmath 更改点的颜色
问题描述
我在 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 似乎并不那么简单。
谢谢!
解决方案
更新:基于 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
}
)
推荐阅读
- python - 我正在努力尝试将会计年度月份列转换为 Python/Pandas 中的日期时间
- angular - Angular & NgRx-Data 更新 & 订阅问题
- ubuntu - 端口 8089 上的 InfluxDB 连接被拒绝
- snowflake-cloud-data-platform - 服务器未能验证请求。(状态代码:401;错误代码:NoAuthenticationInformation)]
- python - 来自激活、损失函数和度量的字符串标识符和实际类名称的不同结果
- javascript - 基于 CSS 类的条件样式(Loop / Foreach)
- java - SpringML-Salesforce,无法从 org.codehaus.stax2.io.Stax2 创建 xmlstreamreader
- java - 截取特定 LinearLayout 的屏幕截图
- sql - 根据行号执行 SQL 更新并使用前一行进行计算
- java - 当孩子被持久化并且父级已经存在时,分离的实体被传递给持久化Spring jpa