Create a web page presentation using R Markdown that features a plot created with Plotly. Host your webpage on either GitHub Pages, RPubs, or NeoCities. Your webpage must contain the date that you created the document, and it must contain a plot created with Plotly. We would love to see you show off your creativity!
The rubric contains the following two questions:
Using independent variable (income) to predict the dependent variable (insurance) with a simple linear regression model would be the plot result.
# Data importing
data('insur', package = 'PoEdata')
df = insur
summary(df)
## insurance income
## Min. : 90.0 Min. : 23.00
## 1st Qu.:160.0 1st Qu.: 39.25
## Median :215.0 Median : 56.00
## Mean :236.9 Mean : 59.30
## 3rd Qu.:300.5 3rd Qu.: 74.00
## Max. :570.0 Max. :140.00
# Model building
mod = lm(insurance ~ income, data = df)
smod = get_regression_points(mod)
# Normal ploting
ggplot(data = df, aes(x = income, y = insurance)) +
geom_point() +
geom_smooth(method = 'lm', se = 0, col = 'red') +
labs(x = 'Family income (1000 dollars)',
y = 'Life insurance held by a family iin $1000 dollars',
title = 'INSURANCE ~ INCOME',
subtitle = 'Intercept = 6.855; Income coef = 3.880')
# Plotly ploting
plot_ly(data = df,
x = ~income,
y = ~insurance,
type = 'scatter',
name = 'Actual') %>%
layout(title = 'INSURANCE ~ INCOME \nIntercept = 6.855; Income coef = 3.880',
xaxis = list(title = 'Family income (1000 dollars)'),
yaxis = list(title = 'Life insurance held by a family iin $1000 dollars')) %>%
add_lines(data = smod,
x = ~income,
y = ~insurance_hat,
type = 'scatter',
mode = 'lines',
name = 'Predict')
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.