Loading packages and the data set

#install.packages("dslabs")
library("dslabs")
## Warning: package 'dslabs' was built under R version 4.2.3
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0     ✔ purrr   1.0.1
## ✔ tibble  3.1.8     ✔ dplyr   1.1.0
## ✔ tidyr   1.3.0     ✔ stringr 1.5.0
## ✔ readr   2.1.3     ✔ forcats 1.0.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(RColorBrewer)
data("brexit_polls")

Expalining the data set

The brexit_polls data set contains polling information about polls that were conducted asking people whether they believed the the UK shoudl remain in the European Union or whether they should leave. Information was collected on the start date of each poll, the end date of each poll, the pollster that was responsible for conducting the poll, the type of poll conducted, the sample size, the proportion of those who wanted to remain in the EU, the proportion of those who wanted to leave to EU, the proportion of those who were undecided, and the spread, which is the difference between the proportions of those who wanted to stay vs. those who wanted to leave.

Creating the plot

theme_set(theme_bw())
ggplot(brexit_polls, aes(x = startdate, y = remain, color = poll_type)) +
  geom_point() +
  labs(title = "Brexit Polling Data Over Time and Poll Type",
       x = "Date",
       y = "Percentage for Remain",
       color = "Poll Type") +
  scale_color_brewer(palette = "Set1")

For this plot, I decided to look at the percentage of people who voted on polls that wanted to remain in the European Union over time, and I decided to add in the third variable, the type of poll that was conducted, to observe both the change in people’s opinions on brexit over time as well as see the relationship between the type of poll conducted and the opinions of those who were polled. I chose to use theme_bw to create a nicer looking border around my scatter plot, and I used the RColorBrewer palette “Set1” in order to create a stark contrast between the points for online polls and telephone polls, since this palette provided two distinctly different and noticeable colors compared to the others I tried.