Interactives

Plotly

library(plotly)
ggplotly(state_election_plot_D1)
1940196019802000202040%50%60%70%
CaliforniaIllinoisPennsylvaniaPercent of democrat votes by stateElection Year


Highcharts

library(highcharter)
state_palette <- setNames(c("#F2A05C", "#8C5A48", "#5C0424"), c("California", "Illinois", "Pennsylvania"))
state_election_votes %>% 
  filter(State %in% c("California", "Illinois", "Pennsylvania")) %>% 
  mutate(demVote = demVote * 100) %>% 
  hchart("line", hcaes(x = Year, y = demVote, group = State), color = state_palette, lineWidth = 3) %>% 
  hc_yAxis(title = list(text = ""), lineWidth = 1, lineColor = 'black', tickWidth = 1, tickColor = 'black',
           gridLineWidth = 0, labels = list(format = '{value}%')) %>% 
  hc_xAxis(title = list(text = ""), lineWidth = 1, lineColor = 'black', tickColor = 'black') %>% 
  hc_legend(verticalAlign = "top", align = "center", floating = TRUE, y = 70) %>% 
  hc_title(text = "Percent of Democrat Votes by State", align = 'left') %>% 
  hc_subtitle(text = "We're a swing state! Go Vote!", align = 'left', style = list(color = 'black')) %>% 
  hc_add_theme(hc_theme(
    chart = list(plotBackgroundColor = 'white'),
    title = list(style = list(fontFamily = "Roboto Slab", fontSize = "25px")),
    subtitle = list(style = list(fontFamily = "Open Sans", fontSize = "16px", fontStyle = 'italic'))
  ))
Created with Highcharts 8.1.2Percent of Democrat Votes by StateWe're a swing state! Go Vote!CaliforniaIllinoisPennsylvania1940195019601970198019902000201030%35%40%45%50%55%60%65%70%