Libraries

## -- Attaching packages ---------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts ------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

Accessing data

sports<-read.csv("https://raw.githubusercontent.com/kitadasmalley/FA2020_DataV
iz/main/data/NFL_fandom_data.csv",
header=TRUE)

Hints from document

sportsT<-sports%>%
gather("sport", "searchInterest",-c(DMA, PctTrumpVote))

sportsT$sport<-factor(sportsT$sport,
 level=c("NBA", "MLB", "NHL", "NFL", "CBB", "NASCAR", "CFB"))

Recreating the Graph

ggplot(sportsT, aes(PctTrumpVote, searchInterest))+
  geom_point(alpha=0.5)+
  geom_smooth(method=lm, se = F)+
  
  facet_wrap(~sport, nrow=1) +
  labs(x = "Trump Vote Share", y = "Search Interest", title = "Donald Trump's 2016 vote share compared with search interest for \n seven major sports, by media market", caption  = "Search interest based on Google Trends data from 2012 to 2017")+
  ylim(0, .5)+
  theme_minimal()+
  theme(axis.text.x = element_blank())
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 11 rows containing non-finite values (stat_smooth).
## Warning: Removed 11 rows containing missing values (geom_point).

ggsave("Recreation.pdf", width = 8, height = 4)
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 11 rows containing non-finite values (stat_smooth).
## Warning: Removed 11 rows containing missing values (geom_point).

Of note: I struggled with how to add just the first and last label to the x axis, and ended up realizing I just didn’t know what to do. I tried exploring annotate to do it manually and tried to read different r functions in the R help, but I think I just do not yet know how to do that.

Creating a new graphic

ggplot(sportsT, aes(PctTrumpVote, searchInterest, group = sport))+
  geom_boxplot(alpha=0.5)+
  labs(x = "Trump Vote Share", y = "Search Interest")+
  ylim(0, .5)+
  theme_minimal()+
  theme(axis.text.x = element_blank())
## Warning: Removed 11 rows containing non-finite values (stat_boxplot).

# Boxplot really didn’t do what I wanted it to do, so I’m moving on

ggplot(sportsT, aes(PctTrumpVote, searchInterest, color=sport)) +
  geom_smooth(method=lm, se = F)+
  scale_color_manual(values = c(NBA = "blue", MLB = 
                                  "blue", NHL = "blue", NFL = "purple", CBB = "red", NASCAR = "red", CFB = "red"))+
  labs(x = "Trump Vote Share", y = "Search Interest", title = "Donald Trump's 2016 vote share compared with search interest for \n seven major sports, by media market", caption  = "Search interest based on Google Trends data from 2012 to 2017")+
  theme_minimal()
## `geom_smooth()` using formula 'y ~ x'

ggsave("New Version.pdf", width = 8, height = 4)
## `geom_smooth()` using formula 'y ~ x'

I tried to use color to show what facet wrap did last time. Things I am wanting to learn from this are how to apply the labels directly next to the lines. But I didn’t know how to do this at this point.