我在R中绘制大量的Spearman相关分析图,我想在图中加入R值标签,但我不想加入p值。我的实际绘图的样本量都很大,所以所有的p值都很小,它们的包含对绘图没有任何帮助。在创建各个图后,我使用 gridExtra::grid.arrange
来组合图,而额外的标签长度会影响到图的输出(将信息包含在图本身之外会更干净)。
我见过改变标签大小和位置的方法,但没有找到任何限制或调整标签内容输出的方法。能否在图中去掉p值?stat_cor
但保留R?有没有其他的包,可以允许更多的定制?
这是我用来制作图的基本代码。
df %>%
ggscatter(x = "Diameter", y = "Depth",
add = "reg.line", conf.int = TRUE,
title = "test",
xlab = "Diameter (m)", ylab = "Depth (m)",
shape = 21, fill = "lightgray", color = "black", size = 3) +
stat_cor(method = "spearman", label.x = 0.45, label.y = 1.2) +
coord_cartesian(ylim = c(0,1.25), xlim = c(0,0.7)) +
theme_minimal()
下面是基本相同的设置,使用 iris
数据集。
ggscatter(data = iris,x = "Sepal.Length", y = "Sepal.Width",
add = "reg.line", conf.int = TRUE,
title = "Iris test",
xlab = "Length", ylab = "Width",
shape = 21, fill = "lightgray", color = "black", size = 3) +
stat_cor(method = "spearman") +
theme_minimal()
从这个github问题中找到了一些提示。https:/github.comkassambaraggpubrissues32。 然后玩转ggplot对象,看看所有不同属性的建立。
ggscatter(data = iris,x = "Sepal.Length", y = "Sepal.Width",
add = "reg.line", conf.int = TRUE,
title = "Iris test",
xlab = "Length", ylab = "Width",
shape = 21, fill = "lightgray", color = "black", size = 3)+
stat_cor(r.digits = 2, method = "spearman",
aes(label = paste("'R = '", ..r.., sep = " "))
)