Skip to content

Commit 9098628

Browse files
committed
2 parents 4249283 + 33cdf55 commit 9098628

File tree

6 files changed

+233
-0
lines changed

6 files changed

+233
-0
lines changed

2024/2024-09-03/20240903.R

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# Load packages -----------------------------------------------------------
2+
3+
library(tidyverse)
4+
library(showtext)
5+
library(camcorder)
6+
library(ggtext)
7+
library(nrBrand)
8+
library(glue)
9+
library(ggalluvial)
10+
11+
12+
# Load data ---------------------------------------------------------------
13+
14+
tuesdata <- tidytuesdayR::tt_load("2024-09-03")
15+
qname_levels_single_response_crosswalk <- tuesdata$qname_levels_single_response_crosswalk
16+
stackoverflow_survey_questions <- tuesdata$stackoverflow_survey_questions
17+
stackoverflow_survey_single_response <- tuesdata$stackoverflow_survey_single_response
18+
19+
20+
# Load fonts --------------------------------------------------------------
21+
22+
font_add_google("Open Sans", "open")
23+
showtext_auto()
24+
body_font <- "open"
25+
26+
27+
# Define colours ----------------------------------------------------------
28+
29+
bg_col <- "grey95"
30+
text_col <- "grey10"
31+
highlight_col <- "#f48024"
32+
33+
34+
# Data wrangling ----------------------------------------------------------
35+
36+
q_data <- stackoverflow_survey_single_response |>
37+
select(years_code_pro, ai_select, ai_threat) |>
38+
drop_na(years_code_pro) |>
39+
mutate(
40+
years_code_pro = case_when(
41+
years_code_pro <= 5 ~ "Less than 5 years",
42+
years_code_pro > 5 & years_code_pro <= 10 ~ "5 - 10 years",
43+
years_code_pro > 10 & years_code_pro <= 20 ~ "10 - 20 years",
44+
years_code_pro > 20 ~ "Over 20 years",
45+
),
46+
years_code_pro = factor(years_code_pro, levels = c(
47+
"Less than 5 years", "5 - 10 years", "10 - 20 years", "Over 20 years"
48+
))
49+
) |>
50+
count(years_code_pro, ai_select, ai_threat) |>
51+
drop_na(ai_select)
52+
53+
plot_data <- q_data |>
54+
left_join(
55+
filter(
56+
qname_levels_single_response_crosswalk, qname == "ai_select"
57+
),
58+
by = c("ai_select" = "level")
59+
) |>
60+
select(-c(qname, ai_select)) |>
61+
rename(ai_select = label) |>
62+
left_join(
63+
filter(
64+
qname_levels_single_response_crosswalk, qname == "ai_threat"
65+
),
66+
by = c("ai_threat" = "level")
67+
) |>
68+
select(-c(qname, ai_threat)) |>
69+
rename(ai_threat = label) |>
70+
mutate(
71+
ai_threat = replace_na(ai_threat, "Did not answer")
72+
) |>
73+
mutate(
74+
ai_select = factor(ai_select, levels = c(
75+
"Yes", "No, but I plan to soon", "No, and I don't plan to"
76+
)),
77+
ai_threat = factor(ai_threat, levels = c(
78+
"Yes", "I'm not sure", "No", "Did not answer"
79+
))
80+
)
81+
82+
83+
plot_data |>
84+
select(years_code_pro, ai_threat, n) |>
85+
group_by(years_code_pro, ai_threat) |>
86+
summarise(n = sum(n)) |>
87+
ungroup() |>
88+
group_by(years_code_pro) |>
89+
mutate(
90+
tot_dev = sum(n),
91+
p = 100 * n / tot_dev
92+
) |>
93+
ungroup() |>
94+
filter(ai_threat == "Yes")
95+
96+
97+
# Start recording ---------------------------------------------------------
98+
99+
gg_record(
100+
dir = file.path("2024", "2024-09-03", "recording"),
101+
device = "png",
102+
width = 7,
103+
height = 6,
104+
units = "in",
105+
dpi = 300
106+
)
107+
108+
109+
# Define text -------------------------------------------------------------
110+
111+
social <- nrBrand::social_caption(
112+
bg_colour = bg_col,
113+
icon_colour = highlight_col,
114+
font_colour = text_col,
115+
font_family = body_font,
116+
twitter = NA
117+
)
118+
title <- "Most developers don't believe AI is a threat to their current job."
119+
st <- glue("The 2024 Stack Overflow Annual Developer Survey, conducted in May
120+
2024, gathered responses from over 65,000 developers. Of those developers who responded with information
121+
about their experience level and whether or not they had used AI,
122+
<span style='color:{highlight_col};'>**developers with less than five years
123+
of professional coding experience**</span>
124+
are most likely to believe that AI is a threat to their current role with 9.6%
125+
answering yes to this question. This compares to just 6.4% of developers with
126+
over 20 years of experience.")
127+
cap <- paste0(
128+
"**Data**: Stack Overflow Annual Developer Survey 2024<br>**Graphic**: ", social
129+
)
130+
131+
132+
# Plot --------------------------------------------------------------------
133+
134+
ggplot(
135+
data = plot_data,
136+
aes(
137+
axis1 = years_code_pro, axis2 = ai_select, axis3 = ai_threat,
138+
y = n
139+
)
140+
) +
141+
geom_alluvium(aes(fill = years_code_pro), alpha = 0.9) +
142+
geom_stratum() +
143+
geom_text(
144+
stat = "stratum",
145+
mapping = aes(label = str_wrap(after_stat(stratum), 10)),
146+
family = body_font,
147+
size = 6,
148+
lineheight = 0.5
149+
) +
150+
labs(
151+
title = title,
152+
subtitle = st,
153+
caption = cap
154+
) +
155+
scale_fill_manual(
156+
values = c(highlight_col, "grey10", "grey40", "grey70")
157+
) +
158+
scale_x_discrete(
159+
limits = c("years_code_pro", "ai_select", "ai_threat"),
160+
labels = str_wrap(c(
161+
"Not including education, how many years have you coded professional?",
162+
"Do you currently use AI tools in your development process?",
163+
"Do you believe AI is a threat to your current role?"
164+
), 18),
165+
position = "top"
166+
) +
167+
coord_cartesian(expand = F) +
168+
theme_void(base_family = body_font, base_size = 22) +
169+
theme(
170+
legend.position = "none",
171+
plot.title = element_textbox_simple(
172+
colour = text_col,
173+
hjust = 0,
174+
halign = 0,
175+
margin = margin(b = 0, t = 5),
176+
lineheight = 0.5,
177+
face = "bold",
178+
size = rel(1.9),
179+
family = body_font
180+
),
181+
plot.subtitle = element_textbox_simple(
182+
colour = text_col,
183+
hjust = 0,
184+
halign = 0,
185+
margin = margin(b = 10, t = 10),
186+
lineheight = 0.5,
187+
family = body_font
188+
),
189+
plot.caption = element_textbox_simple(
190+
colour = text_col,
191+
hjust = 0,
192+
halign = 0,
193+
margin = margin(b = 0, t = 10),
194+
lineheight = 0.5,
195+
family = body_font
196+
),
197+
axis.text.x = element_text(
198+
family = body_font,
199+
colour = text_col,
200+
lineheight = 0.4,
201+
margin = margin(b = 5)
202+
),
203+
plot.margin = margin(10, 10, 10, 10),
204+
plot.background = element_rect(fill = bg_col, colour = bg_col)
205+
)
206+
207+
208+
# Save gif ----------------------------------------------------------------
209+
210+
gg_playback(
211+
name = file.path("2024", "2024-09-03", paste0("20240903", ".gif")),
212+
first_image_duration = 4,
213+
last_image_duration = 20,
214+
frame_duration = .25,
215+
background = bg_col
216+
)
217+
218+
ggsave(
219+
file.path("2024", "2024-09-03", paste0("20240903", ".png")),
220+
height = 6,
221+
width = 7
222+
)

2024/2024-09-03/20240903.gif

1.03 MB
Loading

2024/2024-09-03/20240903.png

417 KB
Loading

2024/2024-09-03/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<h1 align="center"> Stack Overflow Annual Developer Survey 2024 </h1>
2+
3+
<p align="center">
4+
<img src="/2024/2024-09-03/20240903.png" width="60%">
5+
</p>
6+
7+
The making of this visualisation was also recorded using the {camcorder} package.
8+
9+
<p align="center">
10+
<img src="/2024/2024-09-03/20240903.gif" width="60%">
11+
</p>

data/all_weeks.RData

61 Bytes
Binary file not shown.

data/all_weeks.xlsx

429 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)