A 3d visualization of the relationship displacement has on the horsepower, weight and fuel economy.
Code:
fig = plot_ly(mtcars, x = ~disp, y = ~hp, z = ~mpg, height = 600,
marker = list(color = ~wt, showscale = TRUE))
fig = fig %>% add_markers()
fig = fig %>% layout(scene = list(xaxis = list(
title = 'Engine Displacement'),
yaxis = list(title = 'Gross horsepower'),zaxis = list(
title = 'Miles per Gallon')),
annotations = list(x = 1.13, y = 1.03, text = 'Weight in Tons',
xref = 'paper', yref = 'paper', showarrow = FALSE))
line3d = lm(mpg ~ hp + disp, data = mtcars)
fig = fig %>% add_trace(x = mtcars$disp , y = 45.738+.438*mtcars$disp,
z = 30.7359-0.02484*mtcars$hp-0.03035*mtcars$disp,mode = 'lines',
type = "scatter3d", showlegend = FALSE)