【问题标题】:Is there is an equivalent of R's GGally::ggpairs function in python?python中是否有相当于R的GGally::ggpairs函数?
【发布时间】:2021-08-28 19:13:00
【问题描述】:

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"))
  )

有没有办法在 python 中重现这个?

【问题讨论】:

  • 不确定这是否符合您的要求,但我使用情节:plotly.com/python/splom
  • @BrianZ 这很接近,但就像使用标签编码传递分类变量,然后将它们视为任何正常的数值变量,我认为使用不同类型的绘图更合适不同的变量类型。

标签: python plot ggpairs


【解决方案1】:

我喜欢在 R 中使用 ggpairs,发现 seaborn 的 PairGrid 很相似。

您可以指定要放置在每个“布局部分”中的布局样式和绘图类型

您可以在docs 中查看更多示例,但这里是一个示例。

penguins = sns.load_dataset("penguins")
import seaborn as sns
g = sns.PairGrid(penguins, hue="species")
g.map_diag(sns.histplot)
g.map_offdiag(sns.scatterplot)
g.add_legend()

Seaborn PairGrid Example with Penguin Data

【讨论】:

    猜你喜欢
    • 2020-01-16
    • 1970-01-01
    • 2020-11-21
    • 2021-04-05
    • 1970-01-01
    • 2017-05-10
    • 2017-08-21
    • 2015-04-10
    • 2015-08-31
    相关资源
    最近更新 更多