famargar
famargar

Reputation: 3428

How to change regression model in seaborn pairplot

I can create regression plot with seaborns regplot, where I can change the order of the linear regression model with the order option, or choose a lowess model with the lowess=True option as in:

sns.regplot(x='logAssets', y='logLTIFR', lowess=True, data=df, scatter_kws={'alpha':0.15}, line_kws={'color': 'red'})

and obtain this:

enter image description here

Is it possible to change the order of the linear regression in a pairplot?

Or even better, to use a lowess model in seaborn pairplot?

Upvotes: 2

Views: 2521

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40667

For more advanced usage, use PairGrid instead of pairplot. Basically, PairGrid allows you to control which function is used to plot the upper, lower and diagonal plots independently. Check out the documentation for PairGrid for more details.

To answer your specific question:

iris = sns.load_dataset("iris")
g = sns.PairGrid(iris)
g = g.map_upper(sns.regplot, lowess=True, scatter_kws={'alpha':0.15}, line_kws={'color': 'red'})

enter image description here

Upvotes: 4

Related Questions