有没有办法用 显示成对相关值seaborn.pairplot(),如下例所示(用ggpairs()in创建R)?我可以使用附加的代码制作绘图,但不能添加相关性。谢谢
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset('iris')
g = sns.pairplot(iris, kind='scatter', diag_kind='kde')
# remove upper triangle plots
for i, j in zip(*np.triu_indices_from(g.axes, 1)):
g.axes[i, j].set_visible(False)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我想用 ggPairs() 创建一个相关图,其中应该包含
基于@user20650对上述SO问题提供的优秀解决方案,我成功构建了一个函数来生成具有重要性星级的相关值的热图。
不幸的是,当添加(自定义)主题时,彩色 panel.backgrounds 被删除(MWE 在下面提供)。
library(ggplot2)
library(GGally)
# fct. to create heatmap of correlation values with significance stars for upper triangle of ggpairs plot
cor_fun <- function(data, mapping, method="pearson", use="pairwise", ndp=2, sz=5, stars=TRUE, ...){
# grab data
x <- eval_data_col(data, mapping$x)
y <- eval_data_col(data, mapping$y)
# calculate correlation: for significance stars
corr <- cor.test(x, y, method=method)
est <- corr$estimate
lb.size <- sz* abs(est)
# get significance stars
if(stars){
stars …Run Code Online (Sandbox Code Playgroud) GGally::ggpairs函数提供对数字和分类数据类型的支持,使得可以通过几行代码在一个地方查看所有变量之间的交互,但具有很高的灵活性。
这是一个例子:
cols = c("#4c86ad", "#f5dfb3")
insurance_data %>%
dplyr::select(age, bmi, smoker, charges) %>%
GGally::ggpairs(
lower = list(
continuous = GGally::wrap("points", col = cols[1],alpha=0.6),
combo = GGally::wrap("box", fill = "white", col ="black")
),
upper = list(
continuous = GGally::wrap("cor", col = cols[1]),
combo = GGally::wrap("facetdensity", col = "black")
),
diag = list(
continuous = GGally::wrap("barDiag", fill = cols[2], col ="black", bins = 18),
discrete = GGally::wrap("barDiag", fill = cols[2], col ="black"))
)
Run Code Online (Sandbox Code Playgroud)
有没有办法在 python 中重现这个?
有一个ggpairs函数,如何将 x 和 y 的较低刻面的范围限制为例如 0.5?
library(GGally)
xy <- data.frame(matrix(runif(4 * 1000), ncol = 4))
ggpairs(xy)
Run Code Online (Sandbox Code Playgroud)