About
Statement on AI Use
AI tool or model used: DeepSeek
The specific parts of the assignment where AI was used: analysis, visualization
Original work:
- Q4 Analysis: I don’t know how to recode the category variable based on text patterns. Specifically, I was uncertain about how to create a simplified classification (category_simple) that would distinguish entries containing the phrase “Intimate partner or family member” but without a colon (“:”) in the same field.
americas_male_two_categories <- df1 |> filter(region == "Americas", sex == "Male", year == 2023, age == "Total", indicator == "Victims of intentional homicide", dimension == "by relationship to perpetrator", measurement == "Counts") |>
summarise(case_count = sum(value)) |> mutate(percentage = case_count / sum(case_count) * 100)
- Q4 visualization: Central text annotation
p_america_male <- ggplot(americas_male_two_categories, aes(x = "", y = percentage, fill = category_simple)) + geom_col(width = 1, color = "white", linewidth = 3) + coord_polar("y", start = 0) + scale_fill_manual(values = c("Intimate/Family" = "#3182bd", "Other" = "#D5DBDB")) + theme_void() + theme(legend.position = "none", plot.title = element_text(face = "bold", size = 14, hjust = 0.5))
- Interactive plot
library(htmltools) tags$iframe( src = "out/interactive_plot.html", width = "800px", height = "600px" )
- Exact prompts and AI responses
- Q4 Analysis: “I have a column category with text entries. I want to create a new column category_simple where if the entry contains the exact phrase ‘Intimate partner or family member’ AND does NOT contain a colon ‘:’, then label it as ‘Intimate/Family’. Otherwise label it as ‘Other’. Write the R code using dplyr and stringr.”
mutate(category_simple = ifelse(str_detect(category, "Intimate partner or family member") & !str_detect(category, ":"), "Intimate/Family", "Other")) |> group_by(category_simple) |>
- Q4 visualization: “How do I add a percentage label to the center of a pie chart in ggplot2? I have a data frame called americas_male_two_categories with a column percentage. Text should be #3182bd color.”
annotate("text", x = 0, y = 0, label = paste0(round(americas_male_two_categories$percentage[1], 1), "%"), size = 8, fontface = "bold", color = "#3182bd")
- Interactive plot: “How can I hide the code but show the running result?”
#| echo: false #| warning: false #| message: false library(htmltools) tags$iframe( src = "out/interactive_plot.html", width = "800px", height = "600px" )