【1.6】散点图加入关联分析曲线--ggscatter

函数介绍

stat_cor(mapping = NULL, data = NULL, method = "pearson",
label.sep = ", ", label.x.npc = "left", label.y.npc = "top",
label.x = NULL, label.y = NULL, geom = "text", position = "identity",
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)


具体例子：

# Load data
data("mtcars")
df <- mtcars
df$cyl <- as.factor(df$cyl)

# Scatter plot with correlation coefficient
#:::::::::::::::::::::::::::::::::::::::::::::::::
sp <- ggscatter(df, x = "wt", y = "mpg",
add.params = list(color = "blue", fill = "lightgray"), # Customize reg. line
conf.int = TRUE # Add confidence interval
)
sp + stat_cor(method = "pearson", label.x = 3, label.y = 30)


# Color by groups and facet
#::::::::::::::::::::::::::::::::::::::::::::::::::::
sp <- ggscatter(df, x = "wt", y = "mpg",
color = "cyl", palette = "jco",
add = "reg.line", conf.int = TRUE)
sp + stat_cor(aes(color = cyl), label.x = 3)


备注：

library(reshape2)
aaa1 <- aa1[,c(5:6,7,8,9,10)]
aaaa1 <- melt(aaa1,id.vars='V5',value.name="value",variable.name='bq')


参考资料：

http://www.sthda.com/english/rpkgs/ggpubr/reference/stat_cor.html