The data this week comes from Gentry et al. by way of DataIsPlural.
ceodepart <- read_csv("departures.csv")
ceodepart <- ceodepart %>%
unnest_tokens(names, exec_fullname, token = stringr::str_split, pattern = " ") %>%
group_by(co_per_rol) %>%
top_n(n=1) %>%
ungroup() %>%
mutate(departure_code = ifelse(is.na(departure_code), 8, departure_code))
ceodepart %>%
filter(names == "robert" | names == "john" ) %>%
group_by(departure_code) %>%
select(names, departure_code) %>%
table()
## departure_code
## names 1 2 3 4 5 6 7 8 9
## john 1 3 22 3 43 2 27 18 1
## robert 1 1 41 2 137 7 83 33 2
ceodepart %>%
filter(names == "robert" | names == "john" ) %>%
ggplot(aes(x = departure_code)) +
geom_bar(aes(fill = names), position = "fill")
ceodepart %>%
mutate(name_init = ifelse(str_detect(names, "\\."), "initial", names)) %>%
group_by(name_init) %>%
mutate(name_count = n()) %>%
ungroup() %>%
filter(!name_init == "initial") %>%
mutate(name_top = ifelse(name_count > 100, name_init, "another")) %>%
#filter(name_count > 100 & name_init != "initial") %>%
ggplot(aes(x = fyear)) +
geom_bar(aes(fill = name_top), position = "fill") +
xlim(c(1992, 2019)) +
xlab("year") +
ylab("percent") +
scale_fill_viridis_d(direction = -1) +
labs(
title = "First names of departed CEOs",
caption = "Tidy Tuesday Plot: @hardin47 | Data: CEO Departures")