我正在想办法这份报告 http://www.slate.com/features/pkremp_forecast/report.html2016 年美国总统选举的 STAN 模型是使用rmarkdown
:
https://raw.githubusercontent.com/pkremp/polls/master/report.Rmd https://raw.githubusercontent.com/pkremp/polls/master/report.Rmd
我查看了可用的源代码github https://raw.githubusercontent.com/pkremp/polls/master/report.Rmd,其中包含以下行:
# Electoral College
```{r echo=FALSE, message=FALSE, fig.align='center'}
<<plot_ev>>
```
命令<<plot_ev>>
似乎从代码中生成绘图graphs.R https://github.com/pkremp/polls/blob/master/graphs.R:
# Not accounting for the EV allocation rules of Nebraska and Maine
# @knitr plot_ev
ggplot() +
geom_histogram(data = data.frame(ev = result_ev_all_states), aes(ev, fill = ifelse(ev >= 270,"Clinton","Trump")), binwidth = 1) +
scale_fill_manual(values=c("#6E90F8", "#FF6666"), guide = guide_legend(title = "Winner")) +
xlab("Electoral Votes for Clinton") +
theme(axis.ticks.y = element_blank(), axis.text.y = element_blank(), axis.line.y = element_blank(), axis.title.y = element_blank()) +
ggtitle(paste("EV distribution - Pr(Clinton wins) = ", round(mean(result_ev_all_states >= 270)*100, 0), "%", sep = ""))
这是如何运作的?