── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Code
## New packages we'll uselibrary(ggrepel) #<<library(scales) #<<
Attaching package: 'scales'
The following object is masked from 'package:purrr':
discard
The following object is masked from 'package:readr':
col_factor
## Set up long strings as objects, for neatness.p_title <-"Presidential Elections: Popular & Electoral College Margins"p_subtitle <-"1824-2016"p_caption <-"Data for 2016 are provisional."x_label <-"Winner's share of Popular Vote"y_label <-"Winner's share of Electoral College Votes"
Code
p <-ggplot(data = elections_historic, mapping =aes(x = popular_pct, y = ec_pct,label = winner_label))p +geom_hline(yintercept =0.5, size =1.4, color ="gray80") +geom_vline(xintercept =0.5, size =1.4, color ="gray80") +geom_point()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
Code
p <-ggplot(data = elections_historic, mapping =aes(x = popular_pct, y = ec_pct,label = winner_label))p +geom_hline(yintercept =0.5, linewidth =1.4, color ="gray80") +geom_vline(xintercept =0.5, linewidth =1.4, color ="gray80") +geom_point() +geom_text_repel()
Warning: ggrepel: 19 unlabeled data points (too many overlaps). Consider
increasing max.overlaps
Resize it with fig.width and fig.height in the chunk options:
Code
p <-ggplot(data = elections_historic, mapping =aes(x = popular_pct, y = ec_pct,label = winner_label))p_out <- p +geom_hline(yintercept =0.5, size =1.4, color ="gray80") +geom_vline(xintercept =0.5, linewidth =1.4, color ="gray80") +geom_point() +geom_text_repel() +#<<scale_x_continuous(labels =label_percent()) +scale_y_continuous(labels =label_percent()) +labs(x = x_label, y = y_label, #<<title = p_title, subtitle = p_subtitle,caption = p_caption) p_out