Skip to content

Polynomial regression line #311

@MartinGell

Description

@MartinGell

Hi,

I am sorry if this isn't the place for such a question, but I couldn't find any better place to post it to. I need to create a quadratic regression line. In ggplot2 I would add "formula = y ~ poly(x,degree=2)" after "method=lm", how should this be done in plotnine if it is at all possible?

# (if necessary data available here: https://raw.githubusercontent.com/luketudge/stats-tutorials/master/tutorials/data/penguins.csv)

from plotnine import ggplot, geom_point, aes, stat_smooth
import pandas as pd

penguin = pd.read_csv('penguins.csv')

# plot
(ggplot(p, aes('HeartRate', 'Duration'))
 + stat_smooth(method = 'lm')
 + geom_point()
 + labs(y = 'Heart rate (bpm)', x = 'Duration (minutes)'))

Thank you!

Martin

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions