library(ggplot2)
library(tidyverse)
library(googlesheets4)
library(plotly)
library(socsci)
url <- "https://docs.google.com/spreadsheets/d/1npon5F_Gr40HQj8KVeHq_un7SOep4dzc6kjP0px7nLo/edit?usp=sharing"
gs4_deauth()
dt <- range_speedread(url)
dt <- dt |>
mutate(
Q3 = frcode(
Q3 == 1 ~ "Strong Dem",
Q3 == 2 ~ "Democrat",
Q3 == 3 ~ "Independent, lean Democrat",
Q3 == 4 ~ "Independent",
Q3 == 5 ~ "Independent, lean Republican",
Q3 == 6 ~ "Republican",
Q3 == 7 ~ "Strong Republican",
Q3 == 8 ~ "Other"
),
Q4 = frcode(
Q4 == 1 ~ "Approve",
Q4 == 2 ~ "Disapprove"
)
)
dt_2 <- dt |>
filter(Q3 %in% c("Independent, lean Republican", "Republican", "Strong Republican"))
ggplotly(
ggplot(dt_2, aes(x = Q4, fill = Q4)) +
geom_bar() +
scale_fill_manual(values = c("Approve" = "green", "Disapprove" = "red")) +
labs(
title = "Approval Among Republican Respondents",
subtitle = "How is President Trump is Handeling his Job?",
x = "Approval of Donald Trump",
y = "Number of People"
) +
theme_minimal(base_size = 14) +
theme(legend.position = "none")
)Graph Challenge 9
The {plotly} package lets you turn your ggplot figures into interactive ones. You can learn more about it here: https://plotly.com/ggplot2/
For this graph challenge, I want you to create an interactive plot with the April 2025 DU survey data using ggplot and plotly. The type of plot is up to you. So is the variable or variables you’d like to show.
When you’re done, rather than hitting the “render” button, hit the “publish” button to publish your submission to RPubs. Then, submit the link to your publication on Canvas.