问题
I am trying to work out how this report on a STAN model for the 2016 US presidential elections is generated using rmarkdown
:
https://raw.githubusercontent.com/pkremp/polls/master/report.Rmd
I have looked at the source code available on github, which contains lines like:
# Electoral College
```{r echo=FALSE, message=FALSE, fig.align='center'}
<<plot_ev>>
```
The command <<plot_ev>>
seems to generate plots from code in 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 = ""))
How does this work?
来源:https://stackoverflow.com/questions/40967975/what-is-this-knitr-magic-that-produces-a-plot-by-calling-plot-this