library(knitr) opts_chunk$set( fig.align = "center", fig.width = 4, fig.height = 4, crop = TRUE)
library(tidyr) library(purrr) library(dplyr) library(coalitions) library(ggplot2) theme_set(theme_bw())
# load latest emnid data temp <- scrape_wahlrecht() %>% slice(1) %>% collapse_parties() temp %>% unnest("survey") # draw 10k samples from posterior set.seed(29072017) draws <- map(temp$survey, draw_from_posterior, nsim=1e4, correction=0.01) %>% flatten_df() draws_long <- gather(draws, party, percent, cdu:others) %>% group_by(party) %>% mutate(sim = row_number()) %>% ungroup()
ggplot(draws_long, aes(x=party, y=percent)) + geom_boxplot() + geom_hline(yintercept = 0.05, lty=2, col=2) ## chains ggplot(draws_long, aes(x=sim, y=percent)) + geom_path() + geom_hline(yintercept = 0.05, lty=2, col=2) + facet_wrap(~party, nrow=2) draws_long %>% group_by(party) %>% summarize(entryprob = sum(percent >= 0.05)/n())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.