It is easy to get a linear best fit of data in plotnine --using stat_smooth(method="gls")
. However, I can't figure out how to get out the coefficients to the best fit line or the R2 value. Ggplot in R has a stat_regline_equation()
function that does this, but I cannot find a similar tool in plotnine.
Currently, I am using statsmodels.formula.api.ols
to get these values, but there has to be a better way inside of plotnine.
PS: I'm a newbie to all things coding.
stat_regline_equation()
is not a ggplot function, but rather comes from ggpubr extension, so I would not expect it to be a part of plotnine. if you have a working substitute usingstatsmodels.formula.api.ols
you may want to post it here to guide other users, and maybe then someone will be able to improve it for you. – Athematic