'Can you make a Regression Discontinuity Plot using seaborn regplot?

Is there a way to include the variable d in the seaborn regplot so that the discontinuity at x=6 is shown? If not, are there alternatives to seaborn's regplot to create a classical regression discontinuity plot?

import seaborn as sns
import numpy as np

x = np.array([2,4,5.99,6,8,10,12])
d = (x>=6)*1
y = 2*x + 10*d

sns.regplot(x = x, y = y, ci = None )


Solution 1:[1]

Yes but you'd need to use lmplot, which annoyingly requires a dataframe input:

import seaborn as sns
import numpy as np
import pandas as pd

x = np.array([2, 4, 5.99, 6, 8, 10, 12])
d = x >= 6
y = 2 * x + 10 * d
df = pd.DataFrame({"x": x, "y": y, "d": d})

sns.lmplot(data=df, x="x", y="y", hue="d", ci=None)

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mwaskom