Graph Challenge 9

Author

Pierce Patterson

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(googlesheets4)
library(readr)

gs4_deauth()
url <- "https://docs.google.com/spreadsheets/d/1npon5F_Gr40HQj8KVeHq_un7SOep4dzc6kjP0px7nLo/edit?usp=sharing"

dt <- read_sheet(url)

head(dt)
# A tibble: 6 × 274
  StartDate           EndDate             Status Progress Duration (in seconds…¹
  <dttm>              <dttm>               <dbl>    <dbl>                  <dbl>
1 2025-04-14 09:20:59 2025-04-14 09:28:00      0      100                    417
2 2025-04-14 09:20:59 2025-04-14 09:33:00      0      100                    705
3 2025-04-14 09:24:00 2025-04-14 09:33:00      0      100                    539
4 2025-04-14 09:22:00 2025-04-14 09:36:00      0      100                    855
5 2025-04-14 09:20:59 2025-04-14 09:36:00      0      100                    881
6 2025-04-14 09:22:00 2025-04-14 09:36:59      0      100                    932
# ℹ abbreviated name: ¹​`Duration (in seconds)`
# ℹ 269 more variables: Finished <dbl>, RecordedDate <dttm>, ResponseId <chr>,
#   Q1 <dbl>, Q2 <dbl>, Q3 <dbl>, Q4 <dbl>, Q5_1 <dbl>, Q5_2 <dbl>, Q5_3 <dbl>,
#   Q6_1 <dbl>, Q6_2 <dbl>, Q6_3 <dbl>, Q6_4 <dbl>, Q6_5 <dbl>, Q7_1 <dbl>,
#   Q7_6 <dbl>, Q7_38 <dbl>, Q7_36 <dbl>, Q7_7 <dbl>, Q7_19 <dbl>, Q7_20 <dbl>,
#   Q7_33 <dbl>, Q7_22 <dbl>, Q7_32 <dbl>, Q7_31 <dbl>, Q7_8 <dbl>,
#   Q7_39 <dbl>, Q7_15 <dbl>, Q7_27 <dbl>, Q7_16 <dbl>, Q7_DO_1 <dbl>, …
library(ggplot2)
library(plotly)

p <- dt %>%
  ggplot(aes(x = Q2, color = as.factor(Q3), fill = as.factor(Q3))) +
  geom_density(alpha = 0.3) +
  labs(
    title = "Distribution of Ideology by Biden Approval",
    x = "Ideology (1 = Liberal, 7 = Conservative)",
    y = "Density",
    color = "Biden Approval (Q3)",
    fill = "Biden Approval (Q3)"
  ) +
  theme_minimal()

ggplotly(p)