Regression line in Plotly

HI,
How can I extend the regression line in such a way that it touches the axes?



require(plotly)
set.seed(100)
dt=data.frame(
  a=runif(10,0,1),
  b=runif(10,1,10))
ax <- list(
  title = "Measured",
  zeroline = TRUE,
  showline = TRUE,
  showticklabels = TRUE,
  mirror = "ticks",
  showgrid = FALSE,
  range = c(0,1))
ay <- list(
  title = "Synthetic",
  zeroline = TRUE,
  showline = TRUE,
  showticklabels = TRUE,
  mirror = "ticks",
  showgrid = FALSE,
  range = c(1,10))
lm_zero=lm(b~a, data = dt)

plot_ly(dt, x = ~a, y = ~b) %>%
  add_trace(type = 'scatter',mode = 'markers') %>%
    layout( xaxis = ax,yaxis = ay)%>%
    config(mathjax = "cdn") %>% 
    add_lines(x =~a, y = fitted(lm_zero),line = list(color = 'black',dash = 'line')) 

replace with

 add_lines(x =c(0,1), y =predict(lm_zero,newdata = data.frame(a=c(0,1))),...
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.