Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peterdalle/407e46ee4df1689b03c3264a9e8576ad to your computer and use it in GitHub Desktop.
Save peterdalle/407e46ee4df1689b03c3264a9e8576ad to your computer and use it in GitHub Desktop.
Beviljade VR-ansökningar per år uppdelat (2014-2021) på karriärålder
library(dplyr)
library(ggplot2)
library(ggrepel)
library(tidyr)
library(helperutils) # https://github.com/peterdalle/helperutils
# Fil nedladdad från:
# https://www.vr.se/analys/svensk-forskning-i-siffror/vetenskapsradets-forskningsfinansiering-i-siffror.html
file <- "Tillgängliggörande av data_2014-2021.xlsx"
df <- readxl::read_excel(file, sheet = 1)
year_careerage_decisions <- df |>
select(year = År,
careerage = Karriärålder,
decision = Beslut) |>
filter(!careerage %in% c("Saknas", "Org.")) |>
mutate(careerage = factor(careerage, levels = c("0-2", "3-7", "8-12", ">12"), ordered = TRUE),
approved = if_else(decision == "Beviljad", "approved", "not_approved")) |>
group_by(approved, year) |>
count(careerage) |>
pivot_wider(id_cols = everything(), names_from="approved", values_from="n") |>
mutate(percent = approved / (approved + not_approved)) |>
ungroup()
applications <- df |> filter(!Karriärålder %in% c("Saknas", "Org.")) |> count() |> pull()
year_careerage_decisions |>
mutate(careerage_label = paste0(careerage, " år efter disputation"),
careerage_label = if_else(year == 2021, careerage_label, "")) |>
ggplot(aes(year, percent, color=careerage)) +
geom_line(size=1) +
geom_point(size=3) +
geom_text_repel(aes(label=careerage_label, x=2022.5), size=5, direction = "y", min.segment.length = 1000) +
geom_text(aes(label=round(percent * 100)), nudge_y=.008, show.legend=FALSE) +
labs(title = "Forskare med äldre karriärer beviljas oftare pengar från\nVetenskapsrådet – men allt lättare för yngre",
subtitle = glue::glue("Beviljade ansökningar per år. ",
"Baseras på {helperutils::format_swe(applications)} ansökningar. Organisationer uteslutna."),
caption = "@peterdalle",
color = "Antal år efter\ndisputation",
y = NULL,
x = NULL) +
theme_classic() +
theme(plot.title = element_text(size=22, face="bold", lineheight=1.1, margin=margin(b=10)),
plot.subtitle = element_text(size=14, margin=margin(b=30)),
plot.caption = element_text(color="gray"),
legend.position = "none",
axis.line.y = element_blank(),
axis.ticks = element_blank(),
axis.text = element_text(color="black", size=13),
axis.text.y = element_text(margin=margin(r=5)),
axis.text.x = element_text(margin=margin(t=5)),
panel.grid.major.y = element_line(size = 1)) +
scale_color_manual(values = RColorBrewer::brewer.pal(4, "Dark2")) +
scale_y_continuous(labels = scales::label_percent()) +
scale_x_continuous(breaks = unique(year_careerage_decisions$year)) +
guides(color = guide_legend(reverse = TRUE)) +
expand_limits(x = c(2014, 2023.5),
y = c(0.05, .25))
@peterdalle
Copy link
Author

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