Skip to content

Commit

Permalink
Update article (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashsinghal authored Aug 23, 2024
1 parent 1e35796 commit 74b5cc7
Showing 1 changed file with 52 additions and 25 deletions.
77 changes: 52 additions & 25 deletions vignettes/articles/descriptive-analysis-employees.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ knitr::opts_chunk$set(
)
```

```{css, echo=FALSE}
@import url('https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@400;700&display=swap');
table {
font-family: 'Roboto Condensed', sans-serif;
}
```

This article shows how to calculate the descriptive analysis of companies'
employees.

Expand All @@ -24,16 +32,17 @@ options(readr.show_col_types = FALSE)
### Example product-level output of transition risk profile.

```{r, echo=FALSE}
# read_csv("transition_risk_profile_at_product_level_all_countries_wide_22_08_24.csv")
transition_risk_product_example <- product_transition_risk |>
select(any_of(c("companies_id", "min_headcount", "max_headcount", "tilt_sector", "country"))) |>
distinct() |>
mutate(companies_id = ifelse(companies_id == "insecticidal_clownanemonefish",
mutate(companies_id = ifelse(companies_id == "insecticidal_clownanemonefish",
"heliophobic_clownanemonefish", companies_id)) |>
mutate(min_headcount = ifelse(companies_id %in% c("ironhearted_tarpan", "heliophobic_clownanemonefish"),
mutate(min_headcount = ifelse(companies_id %in% c("ironhearted_tarpan", "heliophobic_clownanemonefish"),
50, min_headcount)) |>
mutate(max_headcount = ifelse(companies_id %in% c("ironhearted_tarpan", "heliophobic_clownanemonefish"),
mutate(max_headcount = ifelse(companies_id %in% c("ironhearted_tarpan", "heliophobic_clownanemonefish"),
100, max_headcount)) |>
filter(companies_id %in% c("antimonarchy_canine", "nonphilosophical_llama",
filter(companies_id %in% c("antimonarchy_canine", "nonphilosophical_llama",
"subdermal_chipmunk", "fascist_maiasaura",
"ironhearted_tarpan", "heliophobic_clownanemonefish",
"subzero_whiteeye"))
Expand All @@ -49,68 +58,86 @@ kable(transition_risk_product_example |> head(20))
companies_headcount_range <- transition_risk_product_example |>
select(all_of(c("companies_id", "min_headcount", "max_headcount"))) |>
distinct() |>
mutate(number_of_companies = n_distinct(companies_id), .by = c("min_headcount", "max_headcount")) |>
mutate("# of firms" = n_distinct(companies_id), .by = c("min_headcount", "max_headcount")) |>
select(-all_of(c("companies_id"))) |>
distinct() |>
arrange(min_headcount, max_headcount)
```

```{r, echo=FALSE}
kable(companies_headcount_range, align = "ccc", caption = "Number of companies between range of min_headcount and max_headcount", escape = F) |>
kable_classic(full_width = F, html_font = "Cambria") |>
kable(companies_headcount_range, align = "llc", caption = "# of firms between range of min_headcount and max_headcount", escape = F) |>
kable_classic(full_width = F, html_font = "Roboto Condensed") |>
column_spec(1:3, width = "3cm")
```

### Bar plot

```{r, warning=FALSE, echo=FALSE}
companies_headcount_range$range_headcounts <- paste(companies_headcount_range$min_headcount, companies_headcount_range$max_headcount, sep = '-')
ggplot(companies_headcount_range, aes(x = range_headcounts, y = number_of_companies, fill = range_headcounts)) +
companies_headcount_range_new <- mutate(companies_headcount_range, range_headcounts = paste(min_headcount, max_headcount, sep = '-')) |>
filter(!is.na(min_headcount)) |>
rename("number_of_companies" = "# of firms")
companies_headcount_range_new$range_headcounts <- factor(companies_headcount_range_new$range_headcounts,
levels = unique(companies_headcount_range_new$range_headcounts))
ggplot(companies_headcount_range_new, aes(x = range_headcounts, y = number_of_companies, fill = range_headcounts)) +
geom_bar(stat = "identity") +
labs(title = "Number of companies between range of `min_headcount` and `max_headcount`")
labs(x = "Headcount Range", y = "Number of firms", title = "Number of companies between range of `min_headcount` and `max_headcount`",
fill = "Headcount Range")
```

### Number of companies between range of `min_headcount` and `max_headcount` grouped by `tilt_sector`

```{r, echo=FALSE}
companies_headcount_range_tilt_sector <- transition_risk_product_example |>
select(all_of(c("companies_id", "min_headcount", "max_headcount", "tilt_sector"))) |>
select(all_of(c("companies_id", "tilt_sector", "min_headcount", "max_headcount"))) |>
distinct() |>
mutate(number_of_companies = n_distinct(companies_id), .by = c("min_headcount", "max_headcount", "tilt_sector")) |>
mutate("# of firms" = n_distinct(companies_id), .by = c("tilt_sector", "min_headcount", "max_headcount")) |>
select(-all_of(c("companies_id"))) |>
distinct() |>
arrange(min_headcount, max_headcount, tilt_sector)
filter(tilt_sector %in% c("construction", "industry", "land use")) |>
arrange(tilt_sector, min_headcount, max_headcount)
```

```{r, echo=FALSE}
kable(companies_headcount_range_tilt_sector, align = "cccc", caption = "Number of companies between range of min_headcount and max_headcount grouped by tilt_sector", escape = F) |>
kable_classic(full_width = F, html_font = "Cambria") |>
column_spec(1:4, width = "3cm")
kable(companies_headcount_range_tilt_sector, align = "lllc", caption = "# of firms between range of min_headcount and max_headcount grouped by tilt_sector", escape = F) |>
kable_classic(full_width = F, html_font = "Roboto Condensed") |>
column_spec(1:4, width = "3cm") |>
collapse_rows(columns = 1, valign = "top")
```

### Bar plot

```{r, warning=FALSE, echo=FALSE}
companies_headcount_range_tilt_sector$range_headcounts <- paste(companies_headcount_range_tilt_sector$min_headcount, companies_headcount_range_tilt_sector$max_headcount, companies_headcount_range_tilt_sector$tilt_sector, sep = '-')
ggplot(companies_headcount_range_tilt_sector, aes(x = range_headcounts, y = number_of_companies, fill = range_headcounts)) +
companies_headcount_range_tilt_sector_new <- mutate(companies_headcount_range_tilt_sector, range_headcounts = paste(min_headcount, max_headcount, tilt_sector, sep = '-')) |>
filter(!is.na(min_headcount)) |>
rename("number_of_companies" = "# of firms") |>
arrange(min_headcount, tilt_sector)
companies_headcount_range_tilt_sector_new$range_headcounts <- factor(companies_headcount_range_tilt_sector_new$range_headcounts,
levels = companies_headcount_range_tilt_sector_new$range_headcounts)
ggplot(companies_headcount_range_tilt_sector_new, aes(x = range_headcounts, y = number_of_companies, fill = range_headcounts)) +
geom_bar(stat = "identity") +
labs(title = "Number of companies between range of `min_headcount` and `max_headcount` \n grouped by `tilt_sector`")
labs(x = "Headcount Range", y = "Number of firms", title = "Number of companies between range of \n `min_headcount` and `max_headcount` \n grouped by `tilt_sector`", fill = "Headcount Range") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
```

### Number of companies between range of `min_headcount` and `max_headcount` grouped by `tilt_sector` and `country`

```{r, echo=FALSE}
companies_headcount_range_tilt_sector_country <- transition_risk_product_example |>
select(all_of(c("companies_id", "min_headcount", "max_headcount", "tilt_sector", "country"))) |>
select(all_of(c("companies_id", "tilt_sector", "min_headcount", "max_headcount", "country"))) |>
distinct() |>
mutate(number_of_companies = n_distinct(companies_id), .by = c("min_headcount", "max_headcount", "tilt_sector", "country")) |>
mutate("# of firms" = n_distinct(companies_id), .by = c("tilt_sector", "min_headcount", "max_headcount", "country")) |>
select(-all_of(c("companies_id"))) |>
distinct() |>
arrange(min_headcount, max_headcount, tilt_sector, country)
filter(tilt_sector %in% c("construction", "industry", "land use")) |>
arrange(tilt_sector, min_headcount, max_headcount, country)
```

```{r, echo=FALSE}
kable(companies_headcount_range_tilt_sector_country, align = "ccccc", caption = "Number of companies between range of min_headcount and max_headcount grouped by tilt_sector and country", escape = F) |>
kable_classic(full_width = F, html_font = "Cambria") |>
column_spec(1:5, width = "3cm")
kable(companies_headcount_range_tilt_sector_country, align = "llllc", caption = "# of firms between range of min_headcount and max_headcount grouped by tilt_sector and country", escape = F) |>
kable_classic(full_width = F, html_font = "Roboto Condensed") |>
column_spec(1:5, width = "3cm") |>
collapse_rows(columns = 1, valign = "top")
```

0 comments on commit 74b5cc7

Please sign in to comment.