R⁶ — Disproving Approval

I couldn’t let this stand unchallenged:

Rasmussen makes their Presidential polling data available for both ? & O. Why not compare their ratings from day 1 in office (skipping days that Rasmussen doesn’t poll)?


library(hrbrthemes)
library(rvest)
library(tidyverse)

list(
  Obama="http://m.rasmussenreports.com/public_content/politics/obama_administration/obama_approval_index_history",
  Trump="http://m.rasmussenreports.com/public_content/politics/trump_administration/trump_approval_index_history"
) %>%
  map_df(~{
    read_html(.x) %>%
      html_table() %>%
      .[[1]] %>%
      tbl_df() %>%
      select(date=Date, approve=`Total Approve`, disapprove=`Total Disapprove`)
  }, .id="who") -> ratings

mutate_at(ratings, c("approve", "disapprove"), function(x) as.numeric(gsub("%", "", x, fixed=TRUE))/100) %>%
  mutate(date = lubridate::dmy(date)) %>%
  filter(!is.na(approve)) %>%
  group_by(who) %>%
  arrange(date) %>%
  mutate(dnum = 1:n()) %>%
  ungroup() %>%
  ggplot(aes(dnum, approve, color=who)) +
  geom_hline(yintercept = 0.5, size=0.5) +
  geom_point(size=0.25) +
  scale_y_percent(limits=c(0,1)) +
  scale_color_manual(name=NULL, values=c("Obama"="#313695", "Trump"="#a50026")) +
  labs(x="Day in office", y="Approval Rating",
       title="Presidential approval ratings from day 1 in office",
       subtitle="For fairness, data was taken solely from Trump's favorite polling site (Rasmussen)",
       caption="Data Source: <rasmussenreports.com>\nCode: <https://gist.github.com/hrbrmstr/a7310e1b64d0797401d01d0c6195bd8b>") +
  theme_ipsum_rc(grid="XY", base_size = 16) +
  theme(legend.direction = "horizontal") +
  theme(legend.position=c(0.8, 1.05))

I’ll make a new post occasionally throughout ?’s term.

Cover image from Data-Driven Security
Amazon Author Page

11 Comments R⁶ — Disproving Approval

  1. Rahul S

    Very elegant dplyr code. I haven’t seen a ~{….} structure nor an .id being used before. Could you elaborate on these?

    Reply
    1. hrbrmstr

      ~{} is purrr shorthand for creating an inline anonymous function (e.g. it’s the equivalent of function(.x) {}). When iterating over a named list with map_df(), you can have purrr automatically create a column that’s filled with the value of the name value at each iteration.

      Reply
  2. Pingback: R⁶ — Disproving Approval | A bunch of data

  3. Pingback: R⁶ — Disproving Approval – Cyber Security

  4. Burton Rothberg

    The choice of starting from the beginnings of both admins is somewhat arbitrary. You could just have well as graphed it as a single time series. On that basis T. is about where O. was during most of his presidency. What this really shows is that T. did not get the usual good feelings of a new admin. Not too surprising, considering the polarization of the electorate and the attitude of Dems from day one as “resistance.”

    Reply
    1. hrbrmstr

      No, it’s not. But thanks for sharing your opinion. ? claimed his 50% was higher than any of O’s. It’s misinformation at best and a lie at worst (or in reality). Plain and simple.

      Reply
      1. Burton Rothberg

        median O. “total approval” – 48%
        current T. – 50%
        More generally, picking off an error in a number like this misses why T. won and may be counterproductive. The electorate knew that T. has a big mouth and leads with his lips. They know that H. had a better command of these details, but they didn’t trust her or her (economic) policies. That’s why this kind of criticism, which you also see on late night TV, will do T. no harm. More important is to convince voters that Dems are on their side and making a positive contribution to the polity. Gotcha is exactly wrong.

        Reply
        1. hrbrmstr

          No, this is trying to show him data & facts so he can try to live in reality, not a crony-fabricated, gold-encrusted faux reality show.

          Speaking of facts O’s median rating for first 106 catalogued rankings (to match T’s 106 catalogued rankings by Ramussen) is 61.5%. That’s apples to apples. Nice cherry picking on your part, though.

          And, speaking of picking…I’m not picking off an error in a #. He’s lying, misrepresenting or making stuff up from la la land. I called O out on things. I called C out on things and I’ll keep calling T out on things.

          Finally, Dems are absolutely not on the side of the people. They’re as disingenuous and corrupt as Reps are.

          NOTE: I won’t be responding to or approving further comments in this vein. You’ve clearly got an agenda. Mine is and always has been truth in/through data.

          Reply
  5. Pingback: R⁶ — Disproving Approval – Mubashir Qasim

  6. Buggy Funbunny

    well… Trump has no interest in being the president of the USoA, only of those empty Red states that squeaked out a electoral college enthronement. so, he doesn’t care. and neither will those Red staters, so long as the money flow continues to be: Blue states to DC to Red states (anyone wishing to complain can look it up). once they discover that their only hospital in their corner of God’s country, supported for decades by Medicaid, closes up. well, may be then the data will matter.

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.