polls.16 <- read.csv("http://projects.fivethirtyeight.com/general-model/president_general_polls_2016.csv")


states <- map_data("state")

polls.16.ave <- polls.16 %>%
  mutate(region = tolower(state)) %>%
  group_by(region) %>% 
  summarise(clin.vote.ave = mean(adjpoll_clinton))

states.clinton <- inner_join(polls.16.ave, states, by = "region")
MainStates <- map_data("state")

StatePopulation <- read.csv("https://raw.githubusercontent.com/statsbylopez/DataViz/master/Homeworks/Wiki.States.csv", head = TRUE, sep = ",")

StatePopulation1 <- StatePopulation %>% 
  mutate(region = tolower(State))

states.clinton1 <- inner_join(states.clinton, StatePopulation1, by = "region")
clinton.graph <- ggplot() +
  geom_polygon(data = states.clinton1,
          aes(x = long, y = lat, group = group, fill = clin.vote.ave),
          color = "white", size = 0.5) +
  coord_fixed(1.3) +
  theme_map()

clinton.graph1 <- clinton.graph + scale_fill_continuous(name = " ",
          low = "white", high = "blue", limits = c(20, 60),
          breaks = c(20, 25, 30, 35, 40, 45, 50, 55, 60)) +
          labs(title = "Percent Clinton") +
  theme(legend.position = "right")
clinton.graph1

polls.16.filtered <- polls.16 %>%
  filter(samplesize < 30000, poll_wt > 0)
ggplot(polls.16.filtered, aes(poll_wt, samplesize)) +
  geom_point() +
  geom_smooth(method = "lm") +
  geom_hline(aes(yintercept = 1650)) +
  xlab("Poll Weight") +
  ylab("Sample Size")