R 在ggduo散点图矩阵中显示相关指数

R 在ggduo散点图矩阵中显示相关指数,r,ggplot2,R,Ggplot2,我有这样的想法: library (GGally) df = data.frame(runif(100), rnorm(100), rgamma(100,1,2), rt(100,1), rf(100,1,2)) ggduo(df,columnsX = 1:2, columnsY = 3:5, types = list(continuous = "poin

我有这样的想法:

library (GGally)
df = data.frame(runif(100),
                rnorm(100),
                rgamma(100,1,2),
                rt(100,1),
                rf(100,1,2))

ggduo(df,columnsX = 1:2, columnsY = 3:5,
      types = list(continuous = "points"))

ggduo(df,columnsX = 1:2, columnsY = 3:5,
      types = list(continuous = "cor"))
第一个图显示散点图矩阵,第二个图显示变量之间的相关性

然后我想显示散点图中的相关性。我想我可以通过将几个散点图与
cowplot
合并,但是在
ggduo
中有可能吗


编辑:我发布了一个相关问题。

根据文档,它将显示相关性

library (GGally)
df = data.frame(runif(100),
                rnorm(100),
                rgamma(100,1,2),
                rt(100,1),
                rf(100,1,2))

# from help
PointsWithCor <- function(data, mapping, ..., method = "pearson") {
  x <- eval(mapping$x, data)
  y <- eval(mapping$y, data)
  cor <- cor(x, y, method = method)
  ggally_points(data, mapping, ...) +
    ggplot2::geom_label(
      data = data.frame(
        x = min(x, na.rm = TRUE),
        y = max(y, na.rm = TRUE),
        lab = round(cor, digits = 3)
      ),
      mapping = ggplot2::aes(x = x, y = y, label = lab),
      hjust = 0, vjust = 1,
      size = 5, fontface = "bold",
      inherit.aes = FALSE # do not inherit anything from the ...
    )
}

# plot
ggduo(df,columnsX = 1:2, columnsY = 3:5,
      types = list(continuous = PointsWithCor)))
库(GGally)
df=数据帧(runif(100),
rnorm(100),
rgamma(100,1,2),
rt(100,1),
rf(100,1,2))
#从帮助

PointsWithCor您在文档中看到“心理战”示例了吗?这显示了在通过自定义函数添加相关性的同时使黄土更加平滑。请注意,在当前版本的ggplot2中,
x感谢您的回答,它解决了我问题的第一步。我在编辑中发布了一个链接的问题。太好了!你应该把你的解决方案作为答案。