The Mad Hatter’s Guide to Data Viz and Stats in R
  1. Data Viz and Stats
  2. Case Studies
  3. Gender at the Work Place
  • Data Viz and Stats
    • Tools
      • Introduction to R and RStudio
    • Studio Flow and Data Kits
      • 12-Day Studio Index
      • Healthcare Data Kits
    • Visualization
      • Data
      • Inspect Data
      • Graphs
      • Summaries
      • Counts
      • Quantities
      • Groups
      • Distributions
      • Groups and Distributions
      • Change
      • Proportions
      • Hierarchy
      • Evolution and Flow
      • Ratings and Rankings
      • Surveys
      • Time
      • Space
        • Introduction to Maps
        • What is Vector Data?
        • The Grammar of Maps
        • Interactive Maps with leaflet
      • Networks
      • Miscellaneous Graphing Tools, and References
    • Inference
      • Basics
      • 🎲 Samples
      • Randomization
      • One Mean
      • Two Independent Means
      • Two Paired Means
      • Multiple Means (ANOVA)
      • Correlation
      • One Proportion
      • Two Proportions
    • Modelling
      • Linear Regression
      • Logistic Regression
      • 🕔 Time Series
    • Workflow
      • Facing the Abyss
      • I Publish, therefore I Am
      • Data Carpentry
    • Arts
      • Colours
      • Fonts for Charts
      • Font Effects in Charts
      • Branding and Typography
      • Annotations
      • More Annotations
      • Highlighting
      • Scales
    • AI Tools
      • Using gander and ellmer
      • Using Github Copilot and other AI tools to generate R code
      • Using LLMs to Explain Stat models
    • Case Studies
      • Demo:Product Packaging and Elderly People
      • Ikea Furniture
      • Movie Profits
      • Gender at the Work Place
      • Heptathlon
      • School Scores
      • Children's Games
      • Valentine’s Day Spending
      • Women Live Longer?
      • Hearing Loss in Children
      • California Transit Payments
      • Seaweed Nutrients
      • Coffee Flavours
      • Legionnaire’s Disease in the USA
      • Antarctic Sea ice
      • William Farr's Observations on Cholera in London
    • Projects
      • No Free Hunch

On this page

  • 1 Setting up R Packages
  • 2 Introduction
  • 3 Data
  • 4 Download the Modified data
  • 5 Data Dictionary
  • 6 Plot the Data
  • 7 Task and Discussion
  1. Data Viz and Stats
  2. Case Studies
  3. Gender at the Work Place

Gender at the Work Place

  • Show All Code
  • Hide All Code

  • View Source

1 Setting up R Packages

library(tidyverse)
library(mosaic)
library(skimr)
library(ggformula)
library(scales)

Plot Fonts and Theme

Use _setup.qmd to set these up.

2 Introduction

This is a dataset pertaining to gender and compensation at the workplace, modified for ease of analysis and plotting.

3 Data

Rows: 2,088
Columns: 12
$ year                  <dbl> 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, …
$ occupation            <chr> "Chief executives", "General and operations mana…
$ major_category        <chr> "Management, Business, and Financial", "Manageme…
$ minor_category        <chr> "Management", "Management", "Management", "Manag…
$ total_workers         <dbl> 1024259, 977284, 14815, 43015, 754514, 44198, 10…
$ workers_male          <dbl> 782400, 681627, 8375, 17775, 440078, 16141, 7287…
$ workers_female        <dbl> 241859, 295657, 6440, 25240, 314436, 28057, 3683…
$ percent_female        <dbl> 23.6, 30.3, 43.5, 58.7, 41.7, 63.5, 33.6, 27.5, …
$ total_earnings        <dbl> 120254, 73557, 67155, 61371, 78455, 74114, 62187…
$ total_earnings_male   <dbl> 126142, 81041, 71530, 75190, 91998, 90071, 66579…
$ total_earnings_female <dbl> 95921, 60759, 65325, 55860, 65040, 66052, 55079,…
$ wage_percent_of_male  <dbl> 76.04208, 74.97316, 91.32532, 74.29179, 70.69719…
Data summary
Name jobs_gender
Number of rows 2088
Number of columns 12
_______________________
Column type frequency:
character 3
numeric 9
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
occupation 0 1 5 156 0 522 0
major_category 0 1 7 52 0 8 0
minor_category 0 1 5 46 0 23 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
year 0 1.00 2014.50 1.12 2013.00 2013.75 2014.50 2015.25 2016.0 ▇▇▁▇▇
total_workers 0 1.00 196054.87 375361.03 658.00 18687.00 58997.00 187415.25 3758629.0 ▇▁▁▁▁
workers_male 0 1.00 111515.36 233154.43 0.00 10764.75 32301.50 102643.75 2570385.0 ▇▁▁▁▁
workers_female 0 1.00 84539.51 212696.02 0.00 2364.50 15238.50 63326.50 2290818.0 ▇▁▁▁▁
percent_female 0 1.00 36.00 27.49 0.00 10.73 32.40 57.31 100.0 ▇▃▅▃▂
total_earnings 0 1.00 49762.09 22926.69 17266.00 32410.00 44437.00 61012.00 201542.0 ▇▃▁▁▁
total_earnings_male 4 1.00 53138.06 24765.76 12147.00 35701.50 46825.00 65015.00 231420.0 ▇▃▁▁▁
total_earnings_female 65 0.97 44681.04 21280.84 7447.00 28872.00 40191.00 54813.00 166388.0 ▇▇▂▁▁
wage_percent_of_male 846 0.59 84.03 9.38 50.87 77.56 85.16 90.62 117.4 ▁▃▇▃▁

4 Download the Modified data

5 Data Dictionary

NoteQuantitative Variables

Write in.

NoteQualitative Variables

Write in.

NoteObservations

Write in.

6 Plot the Data

Show the Code
jobs_gender |>
  filter(year == 2016) |>
  filter(major_category == "Healthcare Practitioners and Technical") %>%
  ggplot(aes(workers_female / total_workers,
    total_earnings,
    size = total_workers,
    label = occupation
  )) +
  geom_point() +
  scale_size_continuous(range = c(1, 10)) +
  labs(
    title = "Salaries and Gender Proportion in the Workforce",
    size = "Total # of workers",
    x = "% of workforce reported as female",
    y = "Total Salary in the occupation (Healthcare"
  ) +
  scale_x_continuous(labels = percent_format()) +
  scale_y_continuous(labels = dollar_format()) +
  expand_limits(y = 0)

7 Task and Discussion

Complete the Data Dictionary. Create the graph shown and discuss the following questions:

  • What kind of chart is used in the figure?
  • What geometries have been used and to which variables have these geometries been mapped?
  • Based on this graph, do you think gender plays a role in salaries? What is the trend you see?
  • If SALARY, NO_OF_WORKERS, GENDER, OCCUPATION were available in the original dataset, what pre-processing would have been necessary to obtain this plot?
Back to top
Movie Profits
Heptathlon
Source Code
---
title: <iconify-icon icon="icons8:gender" width="1.2em" height="1.2em"></iconify-icon> Gender at the Work Place
order: 30
code-tools: true
---

## Setting up R Packages

{{< include /_setup_claude_made.qmd >}}


```{r}
#| label: setup
#| message: false
#| warning: false
library(tidyverse)
library(mosaic)
library(skimr)
library(ggformula)
library(scales)
```


```{r}
#| label: pedagogical-packages
#| echo: false
library(downloadthis)
library(glue)
##
###     Adding download buttons
#     data that has been read in
#     {{< downloadthis ../../../../materials/Data/housing_train.csv dname="house_prices" label="Download the House Prices Dataset" icon="database-fill-down" type="info" >}}
#    existing file
#    {{< downloadthis Orange/grouped-summaries.ows dname="grouped_summaries" label="Download the Orange Workflow" icon="database-fill-down" type="info" >}} 
#    
```

#### Plot Fonts and Theme

Use `_setup.qmd` to set these up. 

## Introduction

This is a dataset pertaining to gender and compensation at the workplace, modified for ease of analysis and plotting. 

## Data

```{r}
#| label: read-data
#| echo: false
#| message: false

library(tidytuesdayR)
jobs_gender <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-03-05/jobs_gender.csv")
glimpse(jobs_gender)
skim(jobs_gender)
```


```{r}
#| label: category-checks
#| echo: false

jobs_gender %>% count(major_category)
jobs_gender %>% gf_histogram_interactive( ~ workers_male)
jobs_gender %>% gf_histogram_interactive(~ workers_female)
jobs_gender %>% gf_histogram_interactive(~ total_earnings_male)
jobs_gender %>% gf_histogram_interactive(~ total_earnings_female)

```

## Download the Modified data

```{r}
#| echo: false

library(downloadthis)

jobs_gender %>% 
   downloadthis::download_this(output_name = "job_gender_data", output_extension = ".csv", button_label = "Job and Gender Data", button_type = "default", icon = "fa fa-save")

# 
# mtcars %>%
#   downloadthis::download_this(
#     output_name = "mtcars data set",
#     output_extension = ".csv",
#     button_label = "Download data",
#     button_type = "warning",
#     has_icon = TRUE,
#     icon = "fa fa-save"
#   )
```
## Data Dictionary
::: callout-note
### Quantitative Variables
Write in.

:::

::: callout-note
### Qualitative Variables
Write in.

:::

::: callout-note
### Observations
Write in.

:::


## Plot the Data

```{r}
#| code-fold: true
#| 

jobs_gender |> 
  filter(year == 2016) |> 
  filter(major_category == "Healthcare Practitioners and Technical") %>%
  ggplot(aes(workers_female / total_workers,
             total_earnings,
             size = total_workers,
             label = occupation)) +
  geom_point() +
  scale_size_continuous(range = c(1, 10)) +
  labs(title = "Salaries and Gender Proportion in the Workforce",
       size = "Total # of workers",
       x = "% of workforce reported as female",
       y = "Total Salary in the occupation (Healthcare") +
  scale_x_continuous(labels = percent_format()) +
  scale_y_continuous(labels = dollar_format()) +
  expand_limits(y = 0) 

```

## Task and Discussion
Complete the Data Dictionary.
Create the graph shown and discuss the following questions:

-   What kind of chart is used in the figure?
-   What geometries have been used and to which variables have these geometries been mapped?
-   Based on this graph, do you think gender plays a role in salaries? What is the trend you see?
-   If SALARY, NO_OF_WORKERS, GENDER, OCCUPATION were available in the original dataset, what pre-processing would have been necessary to obtain this plot?

License: CC BY-SA 2.0

Website made with ❤️ and Quarto, by Arvind V.

Hosted by Netlify .