What is this magic that creates the plot, causing <<plot_this>>?

I am trying to figure out how this report is generated in the STAN model for the 2016 US presidential election using rmarkdown:

enter image description here

https://raw.githubusercontent.com/pkremp/polls/master/report.Rmd

I 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 graphs from the 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 it works?

+4
source share

Source: https://habr.com/ru/post/1662807/


All Articles