简体   繁体   English

如何在R中的箱图中添加相关值和p值

[英]how to add correlation value and p-values in boxplot in R

I want to add a computed correlation coefficient and p-value to my boxplot. 我想将计算出的相关系数和p值添加到箱线图中。 This is my code: 这是我的代码:

# Load needed package
library(coin)

# Simulate data
xx <- runif(10)
yy <- runif(10)

# Compute R and p-value
scor <- cor(xx, yy, method = "spearman")
ppp <- spearman_test(xx ~ yy)

# Make plot
boxplot(list(t(xx),t(yy)), main="exprment values", col = c("orange", "yellow"))
legend("topright", bty="n", legend=paste("r=0.69, p=0.0001"))

I want the R and p-value to be printed automatically so I don't have to type them out. 我希望自动打印R和p值,因此不必键入它们。

您可以尝试将字符和数字值粘贴在一起,只需要使用正确的格式即可。

legend("topright", bty="n", legend=paste("r=", scor, ", p=", ppp, sep = ""))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM