library(googlesheets4)
library(plotly)
library(coolorrr)
library(socsci)
library(patchwork)
# Set plot theme and palette
set_palette(
qualitative = "https://coolors.co/393e41-99b2dd-31e981-ef3054-e7bb41",
sequential = "https://coolors.co/f4ffcb-ff2200",
diverging = "https://coolors.co/022f40-d8dbe2-732c2c",
binary = "https://coolors.co/022864-f40119"
)
set_theme()
url <- "https://docs.google.com/spreadsheets/d/1npon5F_Gr40HQj8KVeHq_un7SOep4dzc6kjP0px7nLo/edit?usp=sharing"
gs4_deauth()
dt <- range_speedread(url)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.
plot <- dt |>
dplyr::select(Q24_1, Q24_2, Q24_3, Q24_4, Q24_5, Q24_6, Q24_7) |>
pivot_longer(cols = c(Q24_1, Q24_2, Q24_3, Q24_4, Q24_5, Q24_6, Q24_7),
names_to = "Question",
values_to = "Response") |>
mutate(
Question = frcode(
Question == "Q24_1" ~ "Help with background research",
Question == "Q24_2" ~ "Help summarize reading",
Question == "Q24_3" ~ "Help write a paper",
Question == "Q24_4" ~ "Help edit paper",
Question == "Q24_5" ~ "Help with code",
Question == "Q24_6" ~ "Something else",
Question == "Q24_7" ~ "None of the above"
)
) |>
filter(Response == 1) |>
group_by(Question) |>
summarize(
total_response = n(),
) |>
ggplot() +
aes(y = reorder(Question, total_response), x = total_response, fill = Question) +
geom_bar(stat = "identity") +
labs(
title = "AI Usage for Coursework Help",
subtitle = "Survey responses from Denison students",
x = "Number of Responses",
y = NULL,
caption = "Data: Denison Survey"
) +
theme_minimal() +
theme(
legend.position = "none",
plot.title = element_text(size = 14, face = "bold"),
plot.subtitle = element_text(size = 11, face = "italic"),
plot.caption = element_text(size = 10)
) ggplotly(plot)