library(tidyverse)── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.6
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.1 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.2.0
── 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
# remotes::install_github("avehtari/ROS-Examples",subdir = "rpackage")
hibbs <- rosdata::hibbs |>
mutate(across(growth:vote, \(x) x / 100)) |>
bind_rows(
tribble(
~year, ~growth, ~vote, ~inc_party_candidate, ~other_candidate,
2016, 0.02, 0.5111, "H. Clinton", "Trump",
2020, -0.005, 0.4773, "Trump", "Biden",
2024, NA, 0.492, "Harris", "Trump",
)
)
p1 <- ggplot(hibbs, aes(x = growth, y = vote)) +
geom_hline(aes(yintercept = 0.5), linetype = 3) +
geom_point() +
ggrepel::geom_text_repel(aes(label = year)) +
scale_y_continuous(
"Incumbent party's vote share",
labels = scales::label_percent()
) +
scale_x_continuous(
"Average recent growth in personal income",
labels = scales::label_percent()
)
p1Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_text_repel()`).






















