4

GGally::ggpairs function provides support for both numeric and categorical datatypes, making it possible to see the interactions between all variables in one place, in a few lines of code but with high flexibility.
Here is an example :

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

enter image description here

Is there is any way of reproducing this in python ?

abdelgha4
  • 351
  • 1
  • 16
  • Not sure if this does what you are asking, but I use plotly: https://plotly.com/python/splom/ – Brian Z Aug 28 '21 at 20:22
  • 1
    @BrianZ This is close, but it's just like using label encoding to pass the categorical variables, and then treating them like any normal numeric variable, I think It is more appropriate to use different types of plots for different variable types. – abdelgha4 Aug 29 '21 at 01:38

1 Answers1

5

I love using ggpairs in R, and found seaborn's PairGrid which is similar.

You can specify the layout style and type of plot to place in each "layout section"

You can check out more examples in the docs, but here is one example.

import seaborn as sns
penguins = sns.load_dataset("penguins")
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

Quinten
  • 35,235
  • 5
  • 20
  • 53
Boss Boyd
  • 53
  • 2
  • 6