Here is the code in R that will generate a plotly scatter plot of our data:
mod = lm(circumference ~ age, data=Orange)
x = Orange$age; y = Orange$circumference
x_axis = list(title = "Age", titlefont = list(
family = "Modern Computer Roman"))
y_axis = list(title = "Circumference", titlefont =
list(family = "Modern Computer Roman"))
graph = plot_ly(x = ~x, y = ~y, type = "scatter", mode = "markers",
name = "Data", marker = list(color = "#8B4513",
size = 8)) %>%
add_lines(x = ~x, y = ~fitted(mod), name = "Best Fit",
line = list(color = "#FA9C1C", width = 3)) %>%
layout(xaxis = x_axis, yaxis = y_axis)