table_start <- str_which(table, "% of all workers")
table_end <- str_which(table, "Manager/")
table <- table[1, (table_start + 2 ):(table_end - 1)]
t1 <- glue(table[4], table[6], table[5])
t2 <- glue(table[1], table[2])
t3 <- table[7:16]
table <- c(t2,t1,t3)
table <- str_replace_all(table, "\\s{2,}", "|")
text_con <- textConnection(table)
df <- read.csv(text_con, sep = "|")
text_con <- textConnection(table)
df <- read.csv(text_con, sep = "|")
df <- df %>%
rename(Q1 = X) %>%
rename_at(vars(starts_with("inc")), funs(str_replace(., "inc", "Low.Inc"))) %>%
rename_at(vars(starts_with("Inc")), funs(str_replace(., "Inc", "High.Inc"))) %>%
gather(key = Type, value = Share, All:High.Income)## Q1 Type Share
## 1 Change working hours for some or all employees All 38
## 2 Freeze hiring All 27
## 3 Furlough staff All 23
## 4 Cut back on production All 21
## 5 Ask staff to take pay cuts All 15
## 6 Lay off staff/making staff redundant All 14
df %>% filter(Type %in% c('U.S.', 'UK' )) %>%
ggplot() + theme_fivethirtyeight() + scale_fill_hc() +
geom_bar(aes(y = Share, x = Type, fill = Type),
stat = "identity", position = "dodge") +
facet_wrap(~Q1) +
coord_flip()df %>% filter(Type %in% c("Low.Income", "High.Income")) %>%
ggplot() + theme_fivethirtyeight() + scale_fill_hc() +
geom_bar(aes(y = Share, x = Type, fill = Type),
stat = "identity", position = "dodge") +
facet_wrap(~Q1) +
coord_flip()df %>% filter(Type %in% c("Gen.Z", "Millennials", "Gen.X", "Boomers" )) %>%
ggplot() + theme_fivethirtyeight() + scale_fill_hc() +
geom_bar(aes(y = Share, x = Type, fill = Type),
stat = "identity", position = "dodge") +
facet_wrap(~Q1) +
coord_flip()