Hi,
I'd appreciate any help with this error:
Error: Can't subset columns that don't exist.
x Column RL_Compensation
doesn't exist.
Thank you for your help!!
library(tidyverse)
library(scales)
library(RColorBrewer)
library(dplyr)
library(janitor)
library(readxl)
joanna <- read_excel("Data/ReasonsPartners 2.25.2022.xlsx") %>%
clean_names()
j2 <- joanna %>% select(contains("RL_"))%>%
mutate(id = row_number()) %>%
na.omit() %>% # removing any row with one or more missing values
as.data.frame() %>%
pivot_longer(cols = c(RL_Compensation,RL_Lack_of_Recognition,RL_Family_Circumstances,RL_Commute,RL_Return_to_School,RL_Quality_of_Supervision,RL_Work_Conditions,RL_Health_Reasons,RL_Attractive_Opportunity_Elsewhere)) %>%
mutate(name = str_replace(name, "RL_", ""),
name = str_replace_all(name, "_", " "),
name = str_to_title(name)) %>%
group_by(name) %>%
count(value) %>%
mutate(freq = n / sum(n)) %>%
mutate(value = factor(value, levels = c("Great Extent", "Moderate Extent", "Small Extent", "N/A - Did not contribute")))
j3 <- j2 %>% group_by(name) %>% filter(value == "Great Extent") %>%
ungroup() %>%
mutate(rank = min_rank(desc(freq))) %>%
arrange(desc(freq))
j2 <- j2 %>% mutate(name = factor(name, levels = rev(j3$name)))
display.brewer.all()
ggplot(j2, aes(x = name, y = freq, fill = value)) +
geom_col(position=position_fill(reverse = TRUE)) +
geom_label(aes(x = name, y = freq, label = percent(freq, accuracy = 0.1))) +
geom_text(aes(label=percent(freq, accuracy = 1)),
position=position_stack(vjust=0.5, reverse = TRUE), colour="black", size = 3) +
coord_flip() +
labs(y = NULL, x = NULL, title = "Reasons why people are leaving", subtitle = "Source: Exit Interviews") +
scale_y_continuous(label = percent) +
theme_minimal() +
theme(legend.position = "top",
axis.text.x = element_blank()
) +
scale_fill_brewer(name = "", palette = "Greys", direction = -1) +
theme(axis.text.y=element_text(size=10, color="black", family="sans"))