Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

Quadratic regression line


Please help me on that!

I am trying to plot a quadratic (i.e. 2nd-degree polynomial) regression line.
The code I use is kind of:

qfit <- lm(y ~ poly (x,2))
p <- plot_ly() %>%
… %>%
add_lines (x=x, y=fitted(qfit)) %>%

This gives me that

However, this just links the predicted values (I have 12 of them because I have 12 data points) by straight lines. Instead, what I want is a quadratic fit line between them.
When I try something different, by using

add_trace(x=x, y=~fitted(qfit), type=“scatter”, mode=“lines”, line=list(shape=“spline”))

I get this graph which seems even worse

Does anyone have any advice on how to get what I want?

Thank you in advance,

What I’ve now managed to do is order the data, so that the lines that link the data points are continuous. However, what I get is still not exactly what I want. It is a plot of 12 curved lines, but not a smooth curve line that passes from 12 certain points.
This is what I get

Anyone having any idea on how I could get what I expect?