For this worksheet, we need tidyverse
package as well as
the hibbs data from week 4.
library(tidyverse)
hibbs <- as_tibble(read.csv("../Lec11_files/hibbs.dat", sep = ""))
hibbs |>
ggplot(mapping = aes(x = growth, y = vote)) +
geom_smooth(method = "lm", se = F, color = "red", size = 0.5) +
geom_hline(yintercept = 50, color = "gray") +
geom_point() +
ggrepel::geom_text_repel(mapping = aes(label = year)) +
scale_x_continuous(labels = scales::label_percent(scale = 1)) +
scale_y_continuous(labels = scales::label_percent(scale = 1)) +
labs(x = "Avg recent growth in personal income",
y = "Incumbent party's vote share",
title = "Bread and Peace",
subtitle = "Forecasting the election from the economy",
caption = "Source: Douglas Hibbs") +
theme_classic()
p <- ggplot(mpg, mapping = aes(x = cyl, y = hwy, group = cyl))
p + geom_boxplot()
Install and load the babynames
package.
library(babynames)
robin <- filter(babynames, name == "Robin")
head(robin, 4)
## # A tibble: 4 x 5
## year sex name n prop
## <dbl> <chr> <chr> <int> <dbl>
## 1 1881 M Robin 5 0.0000462
## 2 1887 M Robin 5 0.0000457
## 3 1888 M Robin 6 0.0000462
## 4 1889 M Robin 6 0.0000504
library(babynames)
babynames |>
filter(name == "Robin") |>
ggplot(mapping = aes(x = year, y = n, group = sex, color = sex)) +
geom_line() +
labs(x = "Year", y = "Number",
title = "Number of babies named Robin",
caption = "Source: SSA")