13.5 Plotly: Visualizing statistical results
13.5.1 Dotplots & error bars
fit <- lm(Fertility ~ Catholic + Education + Examination, data = swiss)
# arrange by estimate, then make term a factor to order categories in the plot
d <- broom::tidy(fit) %>%
arrange(desc(estimate))
d <- d[-1,]
plot_ly(d, x = ~estimate, y = ~term, mode = "markers",
marker = list(color = "black")) %>%
add_markers(error_x = ~list(type = "data",
array = d$std.error*2,
color = "black",
width = 3,
thickness = 1),
text = paste(d$std.error)) %>%
layout(margin = list(l = 200),
yaxis = list(title=""),
xaxis = list(title="Estimate"))
13.5.2 Exercise: Dotplots & error bars
- Use the code below to generate a categorical variable that has three values depending on the share of catholics.
- Build three subsets (new datasets) of the dataset according to this variable.
- For all 3 subsets generate coefficient plots with
Fertility
as outcome variable andAgriculture, Examination, Education
as explanatory variables. - Visualize those coefficient plots as small multiples (make the graph publicaton ready!).