Skip to content

Commit 74b5cc7

Browse files
Update article (#41)
1 parent 1e35796 commit 74b5cc7

File tree

1 file changed

+52
-25
lines changed

1 file changed

+52
-25
lines changed

vignettes/articles/descriptive-analysis-employees.Rmd

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ knitr::opts_chunk$set(
99
)
1010
```
1111

12+
```{css, echo=FALSE}
13+
@import url('https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@400;700&display=swap');
14+
15+
table {
16+
font-family: 'Roboto Condensed', sans-serif;
17+
}
18+
```
19+
1220
This article shows how to calculate the descriptive analysis of companies'
1321
employees.
1422

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

2634
```{r, echo=FALSE}
35+
# read_csv("transition_risk_profile_at_product_level_all_countries_wide_22_08_24.csv")
2736
transition_risk_product_example <- product_transition_risk |>
2837
select(any_of(c("companies_id", "min_headcount", "max_headcount", "tilt_sector", "country"))) |>
2938
distinct() |>
30-
mutate(companies_id = ifelse(companies_id == "insecticidal_clownanemonefish",
39+
mutate(companies_id = ifelse(companies_id == "insecticidal_clownanemonefish",
3140
"heliophobic_clownanemonefish", companies_id)) |>
32-
mutate(min_headcount = ifelse(companies_id %in% c("ironhearted_tarpan", "heliophobic_clownanemonefish"),
41+
mutate(min_headcount = ifelse(companies_id %in% c("ironhearted_tarpan", "heliophobic_clownanemonefish"),
3342
50, min_headcount)) |>
34-
mutate(max_headcount = ifelse(companies_id %in% c("ironhearted_tarpan", "heliophobic_clownanemonefish"),
43+
mutate(max_headcount = ifelse(companies_id %in% c("ironhearted_tarpan", "heliophobic_clownanemonefish"),
3544
100, max_headcount)) |>
36-
filter(companies_id %in% c("antimonarchy_canine", "nonphilosophical_llama",
45+
filter(companies_id %in% c("antimonarchy_canine", "nonphilosophical_llama",
3746
"subdermal_chipmunk", "fascist_maiasaura",
3847
"ironhearted_tarpan", "heliophobic_clownanemonefish",
3948
"subzero_whiteeye"))
@@ -49,68 +58,86 @@ kable(transition_risk_product_example |> head(20))
4958
companies_headcount_range <- transition_risk_product_example |>
5059
select(all_of(c("companies_id", "min_headcount", "max_headcount"))) |>
5160
distinct() |>
52-
mutate(number_of_companies = n_distinct(companies_id), .by = c("min_headcount", "max_headcount")) |>
61+
mutate("# of firms" = n_distinct(companies_id), .by = c("min_headcount", "max_headcount")) |>
5362
select(-all_of(c("companies_id"))) |>
5463
distinct() |>
5564
arrange(min_headcount, max_headcount)
5665
```
5766

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

6473
### Bar plot
6574

6675
```{r, warning=FALSE, echo=FALSE}
67-
companies_headcount_range$range_headcounts <- paste(companies_headcount_range$min_headcount, companies_headcount_range$max_headcount, sep = '-')
68-
ggplot(companies_headcount_range, aes(x = range_headcounts, y = number_of_companies, fill = range_headcounts)) +
76+
companies_headcount_range_new <- mutate(companies_headcount_range, range_headcounts = paste(min_headcount, max_headcount, sep = '-')) |>
77+
filter(!is.na(min_headcount)) |>
78+
rename("number_of_companies" = "# of firms")
79+
companies_headcount_range_new$range_headcounts <- factor(companies_headcount_range_new$range_headcounts,
80+
levels = unique(companies_headcount_range_new$range_headcounts))
81+
ggplot(companies_headcount_range_new, aes(x = range_headcounts, y = number_of_companies, fill = range_headcounts)) +
6982
geom_bar(stat = "identity") +
70-
labs(title = "Number of companies between range of `min_headcount` and `max_headcount`")
83+
labs(x = "Headcount Range", y = "Number of firms", title = "Number of companies between range of `min_headcount` and `max_headcount`",
84+
fill = "Headcount Range")
7185
```
7286

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

7589
```{r, echo=FALSE}
7690
companies_headcount_range_tilt_sector <- transition_risk_product_example |>
77-
select(all_of(c("companies_id", "min_headcount", "max_headcount", "tilt_sector"))) |>
91+
select(all_of(c("companies_id", "tilt_sector", "min_headcount", "max_headcount"))) |>
7892
distinct() |>
79-
mutate(number_of_companies = n_distinct(companies_id), .by = c("min_headcount", "max_headcount", "tilt_sector")) |>
93+
mutate("# of firms" = n_distinct(companies_id), .by = c("tilt_sector", "min_headcount", "max_headcount")) |>
8094
select(-all_of(c("companies_id"))) |>
8195
distinct() |>
82-
arrange(min_headcount, max_headcount, tilt_sector)
96+
filter(tilt_sector %in% c("construction", "industry", "land use")) |>
97+
arrange(tilt_sector, min_headcount, max_headcount)
8398
```
8499

85100
```{r, echo=FALSE}
86-
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) |>
87-
kable_classic(full_width = F, html_font = "Cambria") |>
88-
column_spec(1:4, width = "3cm")
101+
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) |>
102+
kable_classic(full_width = F, html_font = "Roboto Condensed") |>
103+
column_spec(1:4, width = "3cm") |>
104+
collapse_rows(columns = 1, valign = "top")
89105
```
90106

91107
### Bar plot
92108

93109
```{r, warning=FALSE, echo=FALSE}
94-
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 = '-')
95-
ggplot(companies_headcount_range_tilt_sector, aes(x = range_headcounts, y = number_of_companies, fill = range_headcounts)) +
110+
companies_headcount_range_tilt_sector_new <- mutate(companies_headcount_range_tilt_sector, range_headcounts = paste(min_headcount, max_headcount, tilt_sector, sep = '-')) |>
111+
filter(!is.na(min_headcount)) |>
112+
rename("number_of_companies" = "# of firms") |>
113+
arrange(min_headcount, tilt_sector)
114+
115+
companies_headcount_range_tilt_sector_new$range_headcounts <- factor(companies_headcount_range_tilt_sector_new$range_headcounts,
116+
levels = companies_headcount_range_tilt_sector_new$range_headcounts)
117+
118+
ggplot(companies_headcount_range_tilt_sector_new, aes(x = range_headcounts, y = number_of_companies, fill = range_headcounts)) +
96119
geom_bar(stat = "identity") +
97-
labs(title = "Number of companies between range of `min_headcount` and `max_headcount` \n grouped by `tilt_sector`")
120+
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") +
121+
theme_minimal() +
122+
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
98123
```
99124

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

102127
```{r, echo=FALSE}
103128
companies_headcount_range_tilt_sector_country <- transition_risk_product_example |>
104-
select(all_of(c("companies_id", "min_headcount", "max_headcount", "tilt_sector", "country"))) |>
129+
select(all_of(c("companies_id", "tilt_sector", "min_headcount", "max_headcount", "country"))) |>
105130
distinct() |>
106-
mutate(number_of_companies = n_distinct(companies_id), .by = c("min_headcount", "max_headcount", "tilt_sector", "country")) |>
131+
mutate("# of firms" = n_distinct(companies_id), .by = c("tilt_sector", "min_headcount", "max_headcount", "country")) |>
107132
select(-all_of(c("companies_id"))) |>
108133
distinct() |>
109-
arrange(min_headcount, max_headcount, tilt_sector, country)
134+
filter(tilt_sector %in% c("construction", "industry", "land use")) |>
135+
arrange(tilt_sector, min_headcount, max_headcount, country)
110136
```
111137

112138
```{r, echo=FALSE}
113-
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) |>
114-
kable_classic(full_width = F, html_font = "Cambria") |>
115-
column_spec(1:5, width = "3cm")
139+
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) |>
140+
kable_classic(full_width = F, html_font = "Roboto Condensed") |>
141+
column_spec(1:5, width = "3cm") |>
142+
collapse_rows(columns = 1, valign = "top")
116143
```

0 commit comments

Comments
 (0)