Description Usage Arguments Details Value Examples
Compare vote totals with a reference dataset. By default, the reference
totals are the state_totals dataset from Dave Leip's Atlas of U.S.Presidential Elections, for candidate
values
of Donald Trump, Hillary Clinton, Gary Johnson, and "Total" (the sum of votes
for these three and all other candidates).
1 2 | compare_votes(.data, reference = NULL, by = c("state_postal", "office",
"candidate"), all.y = FALSE)
|
.data |
Precinct returns dataframe. |
reference |
A dataframe of reference vote totals. See details. |
by |
A vector of shared column names in |
all.y |
Perform a full join, instead of a left join. This will include in the result all rows from the reference dataset. |
We sum votes
in each dataframe by the variables specified in argument by
,
and then left-join .data
and the reference dataframe on the same variables.
A copy of .data
with state-candidate vote totals and their
difference from the reference totals.
1 2 3 4 5 6 7 8 9 | # Use default reference totals from https://uselectionatlas.org
.data = data.frame(office = 'US President', candidate = c('Gary Johnson',
'Donald Trump'), state_postal = 'AL', votes = c(44000, 1318200))
compare_votes(.data)
# Use an arbitrary dataframe for reference totals
reference = data.frame(office = 'US President', candidate = c('Gary Johnson',
'Donald Trump'), state_postal = 'AL', votes = c(43022, 1327200))
compare_votes(.data, reference)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.