htmltools::tags$head(
htmltools::tags$link(
rel = "stylesheet",
href = "https://fonts.googleapis.com/css?family=Arial:400&display=fallback"
)
)
NULL
htmltools::tags$head(
htmltools::tags$link(
rel = "stylesheet",
href = "https://fonts.googleapis.com/css?family=Helvetica+Neue&display=swap"
)
)
NULL
#Install packages
options(repos="https://cloud.r-project.org")
my_packages = c( "tidyverse",
"dplyr",
"data.table",
"visdat",
"ggplot2",
"ggforce",
"extrafont",
"reactable",
"reactablefmtr",
"ggthemes",
"ggtext",
"plotly",
"htmltools",
"janitor",
"showtext")
not_installed = my_packages[!(my_packages %in% installed.packages()[ , "Package"])]
if(length(not_installed)) install.packages(not_installed)
print(paste(length(not_installed), "packages had to be installed."))
## [1] "0 packages had to be installed."
#Load libraries
lapply(my_packages, require, character.only = TRUE, warn.conflicts=FALSE, quietly=TRUE)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Registering fonts with R
## Warning: package 'showtext' was built under R version 4.3.2
## Warning: package 'sysfonts' was built under R version 4.3.2
## Warning: package 'showtextdb' was built under R version 4.3.2
##
## Attaching package: 'showtextdb'
##
## The following object is masked from 'package:extrafont':
##
## font_install
#Import dataset and learn str()
osmi <- read_csv("~/mental health/Mental Health/OSMI 2019 Mental Health in Tech Survey Results.csv")
## New names:
## Rows: 352 Columns: 82
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (55): How many employees does your company or organization have?, Does y... dbl
## (9): Overall, how much importance does your employer place on physical ... lgl
## (18): *Are you self-employed?*, Is your employer primarily a tech compan...
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `Describe the conversation your coworker had with you about their mental
## health (please do not use names).` -> `Describe the conversation your
## coworker had with you about their mental health (please do not use
## names)....19`
## • `Describe the conversation your coworker had with you about their mental
## health (please do not use names).` -> `Describe the conversation your
## coworker had with you about their mental health (please do not use
## names)....45`
## • `Why or why not?` -> `Why or why not?...61`
## • `Why or why not?` -> `Why or why not?...63`
str(osmi)
#Change names
setnames(osmi, c('*Are you self-employed?*',
"How many employees does your company or organization have?",
'Is your primary role within your company related to tech/IT?',
'Has your employer ever formally discussed mental health (for example, as part of a wellness campaign or other official communication)?',
'Is your anonymity protected if you choose to take advantage of mental health or substance abuse treatment resources provided by your employer?',
'If a mental health issue prompted you to request a medical leave from work, how easy or difficult would it be to ask for that leave?',
'Does your employer provide mental health benefits as part of healthcare coverage?',
'Do you know the options for mental health care available under your employer-provided health coverage?',
'Would you feel comfortable discussing a mental health issue with your direct supervisor(s)?',
'Does your employer offer resources to learn more about mental health disorders and options for seeking help?',
'Have you ever discussed your mental health with your employer?',
'Overall, how much importance does your employer place on physical health?',
'Overall, how much importance does your employer place on mental health?',
'Do you have medical coverage (private insurance or state-provided) that includes treatment of mental health disorders?',
'Do you know local or online resources to seek help for a mental health issue?',
'What is your gender?'),
c('self-employed',
'totalEmp',
'roleRelatedToTech',
'employerFormalDisc',
'anonymity',
'askForLeaveEase',
'empHealthIns',
'healthInsOpt',
'comfort',
'empResources',
'employeeDisc',
'physHealthImp',
'mentHealthImp',
'medIns',
'resources',
'gender'))
#Check renaming
str(osmi)
#Check for duplicate rows
get_dupes(osmi)
## No variable names specified - using all columns.
## No duplicate combinations found of: self-employed, totalEmp, Is your employer primarily a tech company/organization?, roleRelatedToTech, empHealthIns, healthInsOpt, employerFormalDisc, empResources, anonymity, ... and 73 other variables
#Shorten answer name so it's easier to make visualizations/charts
osmi[,5][osmi[,5]== 'Not eligible for coverage / NA'] <- 'Ineligible/NA'
osmi[,c(5,7:10)][osmi[,c(5,7:10)]== "I don't know"] <- 'Unsure'
osmi[,10][osmi[,10]== 'Neither easy nor difficult'] <- 'Neither'
# In col 6, it can be confusing that there is an "NA" because it's actually meant to be a valid answer. Change to "Doesn't apply."
osmi[,6][osmi[,6]== 'N/A'] <- "Doesn't apply"
#Change factor levels for cols 7-9
osmi[,7:9] <- lapply(osmi[,7:9], levels = c("Unsure", "No", "Yes"), factor)
#Make askForLeaveEase levels and check
osmi$askForLeaveEase <- factor(osmi$askForLeaveEase, levels=c(
"Unsure",
"Very easy",
"Somewhat easy",
"Neither",
"Somewhat difficult",
"Difficult"))
#Change factors to "Y,N,M"
osmi$comfort<- factor(osmi$comfort, levels=c("No", "Maybe", "Yes"))
#Focus on data that is about current employer, not past one
osmi <- osmi[, c(1:23, 26:29, 77)]
osmi
## # A tibble: 352 × 28
## `self-employed` totalEmp Is your employer primarily a tec…¹ roleRelatedToTech
## <lgl> <chr> <lgl> <lgl>
## 1 FALSE 26-100 TRUE TRUE
## 2 FALSE 26-100 TRUE TRUE
## 3 FALSE 26-100 TRUE TRUE
## 4 FALSE 100-500 TRUE TRUE
## 5 FALSE 26-100 TRUE TRUE
## 6 FALSE 100-500 TRUE FALSE
## 7 FALSE 26-100 TRUE TRUE
## 8 TRUE <NA> NA NA
## 9 FALSE 26-100 TRUE TRUE
## 10 FALSE 25-Jun TRUE TRUE
## # ℹ 342 more rows
## # ℹ abbreviated name:
## # ¹`Is your employer primarily a tech company/organization?`
## # ℹ 24 more variables: empHealthIns <chr>, healthInsOpt <chr>,
## # employerFormalDisc <fct>, empResources <fct>, anonymity <fct>,
## # askForLeaveEase <fct>,
## # `Would you feel more comfortable talking to your coworkers about your physical health or your mental health?` <chr>, …
#Get rid of true for self-employed because we'll be more interested in how they interact with boss and employees and insurance from employees
osmi <- osmi %>% filter(roleRelatedToTech == "TRUE")
#Confirm change
summary(osmi)
#Check for categories in all columns to check for errors or misspellings
osmiUnq <- lapply(osmi, unique)
osmiUnq
#Some were dates instead of # of employees. Change June 25 to 6-25 and "5-Jan" to 1-5 employees
osmi[,2][osmi[,2]== '25-Jun'] <- '6-25'
osmi[,2][osmi[,2]== '5-Jan'] <- '1-5'
#Check change
unique(osmi$totalEmp)
#Drop columns that are all NA
osmi <- osmi[,c(1:21,28)]
str(osmi)
#Consolidate genders while respectfully leaving diverse answers. There should be nine unique answers.
osmi<- osmi %>% mutate(genderUpdated = factor(gender) %>%
fct_recode(
m = "Make",
m = "male",
m= "M",
m= "Identify as male",
m="Cishet male",
m= "Male",
m= "Cis Male",
m= "CIS Male",
m= "Man",
m= "Masculine",
m= "masculino",
m= "Let's keep it simple and say \"male\"",
f= "female",
f= "cis woman",
f= "F",
f= "Female",
f= "Female (cis)",
f= "cis woman",
f= "femmina",
f= "Femile",
f= "Woman",
nb = "Non-binary",
nb = "Non binary",
nb = "Nonbinary"))
osmi <- osmi[complete.cases(osmi$genderUpdated), ]
print(osmi)
## # A tibble: 277 × 23
## `self-employed` totalEmp Is your employer primarily…¹ roleRelatedToTech
## <lgl> <chr> <lgl> <lgl>
## 1 FALSE 26-100 TRUE TRUE
## 2 FALSE 26-100 TRUE TRUE
## 3 FALSE 26-100 TRUE TRUE
## 4 FALSE 100-500 TRUE TRUE
## 5 FALSE 26-100 TRUE TRUE
## 6 FALSE 26-100 TRUE TRUE
## 7 FALSE 6-25 TRUE TRUE
## 8 FALSE 100-500 TRUE TRUE
## 9 FALSE More than 1000 TRUE TRUE
## 10 FALSE 500-1000 TRUE TRUE
## # ℹ 267 more rows
## # ℹ abbreviated name:
## # ¹`Is your employer primarily a tech company/organization?`
## # ℹ 19 more variables: empHealthIns <chr>, healthInsOpt <chr>,
## # employerFormalDisc <fct>, empResources <fct>, anonymity <fct>,
## # askForLeaveEase <fct>,
## # `Would you feel more comfortable talking to your coworkers about your physical health or your mental health?` <chr>, …
#Check for 9 unique categories
unique(osmi$genderUpdated)
## [1] m f
## [3] nb None
## [5] agender Questioning
## [7] Agender trans woman Trans man
## [9] Trans non-binary/genderfluid
## 9 Levels: agender Agender trans woman m f nb None Questioning ... Trans non-binary/genderfluid
#Drop old gender col
osmi <- osmi [,-22]
#Check numeric columns for any typos (should be 0-10) or any misspellings
summary(osmi)
#Check that all columns are the right class
osmi$totalEmp <- factor(osmi$totalEmp, levels=c("1-5", "6-25", "26-100", "100-500", "500-1000", "More than 1000"))
#Check totalEmp
unique(osmi$totalEmp)
#Make a table with the frequency with which people rated their employer's importance on mental health
table(osmi$mentHealthImp)
freqMH <- data.frame(rating= c(0:10), freq=c(21, 16, 24, 35, 20, 70, 28, 38, 30, 10, 12))
class(freqMH$rating)
class(freqMH$freq)
#Convert to numeric
freqMH$rating <- as.numeric(freqMH$rating)
class(freqMH$rating)
ggsave("mentHealth.png")
## Saving 7 x 5 in image
## Saving 7 x 5 in image
The rounded percentages vary from 0-8% (with 1 response rounding to 0%) and correspond to how easy it would be to ask for mental health leave with regards to whether that person also has mental health insurance benefits and has received employer communication.
If a high percentage of people who have the same answer to mental health benefits and an employer communication rate that it would be easy to ask for leave and a low percent of those people say it would be difficult, their answer could possibly be related to their employer's actions.
There are over fifty combinations, and you can use the filters under benefits on the left and then click another column or type a response in to sort and see specific combinations.