Graph Challenge 9

Author

Tiansheng Gao

Published

April 28, 2025

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.

library(tidyverse) 
library(googlesheets4) 
library(plotly)
gs4_deauth() 
range_speedread( 
"https://docs.google.com/spreadsheets/d/1npon5F_Gr40HQj8KVeHq_un7SOep4dzc6kjP0px7nLo/edit?usp=sharing" 
) -> April_2025
political_interest <- April_2025 %>%
  filter(!is.na(Q2)) %>%
  mutate(Q2 = recode(Q2,
                     `1` = "1 - Extremely Interested",
                     `2` = "2 - Very Interested",
                     `3` = "3 - Moderately Interested",
                     `4` = "4 - Slightly Interested",
                     `5` = "5 - Not Interested at All")) %>%
  count(Q2) %>%
  mutate(percent = n / sum(n)) %>%
  ggplot(aes(x = Q2, y = percent)) +
  geom_col(fill = "skyblue") +
  labs(
    title = "Political Interest among Students (April 2025 Survey)",
    x = "Level of Political Interest",
    y = "Percentage"
  ) +
  scale_y_continuous(labels = scales::percent) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))  # Rotate x-axis labels a little for better reading

ggplotly(political_interest)