在ggduo散点图中显示相关指数 [英] Show correlation index in ggduo scatterplot matrix
本文介绍了在ggduo散点图中显示相关指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的东西:
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"))
第一个图显示了散点图矩阵,第二个图显示了变量之间的相关性.
The first plot shows a matrix of scatterplots , and the second shows the correlations between variables.
然后,我想在散点图中显示相关性.我想可以通过将几个散点图与 cowplot
合并来做到这一点,但是在 ggduo
中是否有可能?
Then I'd like to display the correlations in the scatterplots. I think I can do it by merging several scatterplots with cowplot
, but is it possible within ggduo
?
I posted a related question here.
推荐答案
根据文档,它将显示相关性.
According to the document, it will display the correlation.
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)))
这篇关于在ggduo散点图中显示相关指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文