library(plotly)
mymodel <- lm(r_shift ~ median_income16 + any_college,
data = cali_counties, weight = pop_estimate16)
p <- plot_ly( data = cali_counties,
x = ~median_income16,
y = ~any_college,
z = ~r_shift) %>%
add_marginals(model = mymodel)
Run the code above in your browser using DataLab