Stéphane Laurent
Stéphane Laurent

Reputation: 84519

Dashed trend line with R plotly

How to get a dashed trend line with the plotly package ? According to the documentation, it should be:

dat <- iris[,2:3]
colnames(dat) <- c("x","y")
p <- plot_ly(dat, x = x, y = y, type="scatter", mode="markers", name="data")
add_trace(p, x = x, y = fitted(lm(y~x, data=dat)), line = list(dash="dashed"), name="regression line")

But the trend line is solid.

Upvotes: 6

Views: 9555

Answers (1)

J.Wadhwa
J.Wadhwa

Reputation: 101

What you can do here is run a regression and then add the fitted line for the same in your code. The syntax for the same is:

add_lines(x= ~label1, y= fitted(fit1), name = "",
          line = list(color= c_yellow2, widthh=0.5, dash="dot"))

Upvotes: 8

Related Questions