Skip to content

Instantly share code, notes, and snippets.

@mine-cetinkaya-rundel
Created January 31, 2025 01:34
Show Gist options
  • Save mine-cetinkaya-rundel/933e82db50257e578940a8509127e479 to your computer and use it in GitHub Desktop.
Save mine-cetinkaya-rundel/933e82db50257e578940a8509127e479 to your computer and use it in GitHub Desktop.
# Remake of plot from https://www.kdnuggets.com/data-science-salaries-job-market-analysis-2024-2025
# load packages
library(tidyverse)
library(scales)
# create data frame
ds_salaries <- tribble(
~experience, ~salary, ~label,
0.5, 117276, "0-1 years",
2, 128403, "1-3 years",
5, 141390, "4-6 years",
8, 152966, "7-9 years",
12, 166818, "10-14 years",
15, 189884, "15+ years"
)
# plot
ggplot(
ds_salaries,
aes(x = experience*3, y = salary)
) +
geom_col(width = 4, fill = "#e8c95c") +
labs(
x = "Median yearly total compensation for data scientists in the US by years of experience (Glassdoor)",
y = NULL,
title = "Data Science Salaries\nby Experience Level"
) +
geom_text(
aes(y = salary + 20000, label = str_to_upper(label)),
color = "lightgray", fontface = "bold", size = 3
) +
geom_text(
aes(y = salary + 10000, label = dollar(salary)),
color = "#75b6be", fontface = "bold", size = 4
) +
theme_void() +
theme(
plot.background = element_rect(fill = "black"),
plot.title = element_text(color = "#e8c95c", face = "bold", hjust = 0.5, size = 25),
axis.title.x = element_text(color = "white", size = 10, margin = margin(t = 2.5, b = 2.5, l = 0, r = 0))
)
@mine-cetinkaya-rundel
Copy link
Author

The original plot from KD Nuggets:

ebee33b9-ceb6-fe2b-3469-82278697749e

The updated plot with code above, scaling x and y axes correctly:

data-science-salaries png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment