调整 R 中 stat_cor 的 Spearman 相关性的标签输出

Adjusting label output of stat_cor's Spearman's correlation in R

我正在 R 中绘制大量 Spearman 相关分析。我想在图中包含 R 值标签,但我不想包含 p 值。我的实际绘图的样本量都很大,所以所有 p 值都很小,它们的包含不会为绘图增加任何有用的东西。在创建单独的图之后,我使用 gridExtra::grid.arrange 来组合图,并且额外的标签长度​​妨碍了(更清晰地包括图本身之外的信息)。

我见过改变标签大小和位置的方法,但没有发现任何限制或调整标签内容输出的方法。是否可以从 stat_cor 中的图中删除 p 值但保留 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.com/kassambara/ggpubr/issues/32 然后使用 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 = " "))
  )