# \donttest{
library(eiExpand)
data(example_rpvDF)
# Note that these plots are designed to be
# saved as a png using ggplot2::ggsave(). See first example for recommending
# sizing, noting that height and weight arguments may need adjusting
# depending on plot attributes such as number of contests and paneling
# plot county-level results with all defaults
rpvDF_county <- example_rpvDF %>% dplyr::filter(Jurisdiction == "County")
rpv_plot(rpvDF_county)
# save to png with recommended sizing
# ggplot2::ggsave("rpv_plot_default.png", height = 10, width = 15)
# include CI bands
rpv_plot(rpvDF_county, includeErrorBand = TRUE)
# include CI bands with estimate labels outside bar
rpv_plot(
rpvDF_county,
includeErrorBand = TRUE,
txtInBar = FALSE
)
# panel by preferred candidate
rpvDF_county$Year <- paste(rpvDF_county$Year,
"\n") # so contest and year are on different lines
rpvDF_county$Preferred_Candidate <- paste(rpvDF_county$Preferred_Candidate,
"\nPreferred Candidate")
rpv_plot(
rpvDF_county,
panel_spacing = 6,
panelBy = "Preferred_Candidate"
)
# plot all jurisdictions with panels
rpv_plot(example_rpvDF, panelBy = "Jurisdiction")
# add contest separation shading
rpv_plot(
example_rpvDF,
panelBy = "Jurisdiction",
contest_sep = "s"
)
# plot panels by voter_race and remove legend
rpv_plot(rpvDF_county,
panel_spacing = 6,
panelBy = "Voter_Race") +
ggplot2::theme(legend.position="none")
# }
Run the code above in your browser using DataLab