Last active
August 14, 2018 16:36
-
-
Save mschnetzer/89df890c79f85a078cb7e4baa85ed631 to your computer and use it in GitHub Desktop.
Change in ratio part/full time employees 2007-2017 (https://twitter.com/matschnetzer/status/1024882484255903744)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adapted from https://jschoeley.github.io/2018/06/30/bubble-grid-map.html | |
library(eurostat) | |
library(tidyverse) | |
library(lubridate) | |
library(sf) | |
library(lwgeom) | |
library(msthemes) | |
# download eurostat data for nuts 2 regions | |
euro_job <- | |
get_eurostat('lfst_r_lfe2eftpt', stringsAsFactors = FALSE) %>% | |
filter(sex == 'T', | |
str_length(geo) == 4, # NUTS-2 | |
worktime %in% c("FT","PT") | |
) | |
# download geospatial data for NUTS-2 regions | |
eu_nuts2_sf <- | |
get_eurostat_geospatial(output_class = 'sf', | |
resolution = '60', nuts_level = 2) | |
# divide the european continent into a 150 by 150 cell grid | |
euro_grid <- | |
st_make_grid(eu_nuts2_sf %>% filter(LEVL_CODE == 2), n = 150) | |
# calculate share of FT/PT in total employment and change between 2005 and 2017 | |
euro_job_share <- | |
euro_job %>% | |
spread(worktime,values) %>% | |
mutate(ratio = PT/FT*100) %>% | |
filter(year(time) %in% c(2007,2017)) %>% | |
mutate(ratioch = (lead(ratio)-ratio)/ratio*100) %>% | |
filter(year(time)==2007) | |
# prepare data and plot bubble-grid-map of EU population change | |
eu_nuts2_sf %>% | |
left_join(y = euro_job_share, by = c('id' = 'geo')) %>% | |
select(ratioch) %>% | |
st_interpolate_aw(to = euro_grid, extensive = TRUE) %>% | |
st_centroid() %>% | |
cbind(st_coordinates(.)) %>% | |
arrange(abs(ratioch)) %>% | |
filter(!is.na(ratioch)) %>% | |
# draw a dot at each grid cell and scale it in area according | |
# to absolute size of population change and color it according | |
# to direction of population change | |
ggplot() + | |
geom_sf(data=eu_nuts2_sf,fill = "grey98", color = NA) + | |
geom_point(aes(x = X, y = Y, | |
size = abs(ratioch), | |
fill = ifelse(ratioch >= 0, 'pos', 'neg')), | |
shape = 21, color = 'white', show.legend = FALSE) + | |
coord_sf(ylim = c(36, 70), xlim = c(-19, 40), datum=NA, crs = st_crs(eu_nuts2_sf)) + | |
scale_size_area(max_size = 8) + | |
scale_fill_manual(values = msc_palette[c(1,4)]) + | |
theme_ms_line(grid=F) + theme(axis.text = element_blank()) + | |
labs(x="",y="",title="Part time work on the advance",subtitle="Change in ratio part/full time employees 2007-2017",caption="Source: EUROSTAT. Chart: @matschnetzer") + | |
ggsave(filename="ptftbubble.png", width=5, height=5,dpi=600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment