将 p 值的星号添加到相关矩阵 R
add star of p value to correlation matrix R
我正在使用本网站的代码绘制散点图和相关矩阵:http://www.sthda.com/english/wiki/scatter-plot-matrices-r-base-graphs
panel.cor <- function(x, y){
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- round(cor(x, y), digits=2)
txt <- paste0("R = ", r)
cex.cor <- 0.8/strwidth(txt)
text(0.5, 0.5, txt, cex = cex.cor * r)
}
# Customize upper panel
upper.panel<-function(x, y){
points(x,y, pch = 19, col = my_cols[iris$Species])
}
# Create the plots
pairs(iris[,1:4],
lower.panel = panel.cor,
upper.panel = upper.panel)
如何计算p值并在相关系数旁边加星?我发现 "PerformanceAnalytics" 包可以做到这一点,但我想在上面板散点图中使用 smoothScatter 函数。我不知道如何在 PerformanceAnalytics 中使用 smoothScatter 函数。
目前我的上面板功能看起来像这样。这是从另一个网站复制的
pairs(df, lower.panel = panel.cor,
upper.panel = function(...) smoothScatter(..., nrpoints = 0, add = TRUE), gap = 0.2)
r2 <- cor.test(x, y)$p.value
r3 <- symnum(r2, cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***","**","*",""))
可用于获取p值
所以整个 panel.cor 函数看起来像这样:
panel.cor <- function(x, y){
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- round(cor(x, y), digits=2)
r2 <- cor.test(x, y)$p.value
r3 <- symnum(r2, cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***","**","*",""))
txt <- paste(r, r3, sep = " ")
cex.cor <- 0.8/strwidth(txt)
text(0.5, 0.5, txt, cex = cex.cor*r)
}
我正在使用本网站的代码绘制散点图和相关矩阵:http://www.sthda.com/english/wiki/scatter-plot-matrices-r-base-graphs
panel.cor <- function(x, y){
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- round(cor(x, y), digits=2)
txt <- paste0("R = ", r)
cex.cor <- 0.8/strwidth(txt)
text(0.5, 0.5, txt, cex = cex.cor * r)
}
# Customize upper panel
upper.panel<-function(x, y){
points(x,y, pch = 19, col = my_cols[iris$Species])
}
# Create the plots
pairs(iris[,1:4],
lower.panel = panel.cor,
upper.panel = upper.panel)
如何计算p值并在相关系数旁边加星?我发现 "PerformanceAnalytics" 包可以做到这一点,但我想在上面板散点图中使用 smoothScatter 函数。我不知道如何在 PerformanceAnalytics 中使用 smoothScatter 函数。 目前我的上面板功能看起来像这样。这是从另一个网站复制的
pairs(df, lower.panel = panel.cor,
upper.panel = function(...) smoothScatter(..., nrpoints = 0, add = TRUE), gap = 0.2)
r2 <- cor.test(x, y)$p.value
r3 <- symnum(r2, cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***","**","*",""))
可用于获取p值
所以整个 panel.cor 函数看起来像这样:
panel.cor <- function(x, y){
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- round(cor(x, y), digits=2)
r2 <- cor.test(x, y)$p.value
r3 <- symnum(r2, cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***","**","*",""))
txt <- paste(r, r3, sep = " ")
cex.cor <- 0.8/strwidth(txt)
text(0.5, 0.5, txt, cex = cex.cor*r)
}