diff --git a/vignettes/articles/descriptive-analysis-amount_of_companies.Rmd b/vignettes/articles/descriptive-analysis-amount_of_companies.Rmd index f92e16a..2f6ab33 100644 --- a/vignettes/articles/descriptive-analysis-amount_of_companies.Rmd +++ b/vignettes/articles/descriptive-analysis-amount_of_companies.Rmd @@ -18,53 +18,25 @@ library(dplyr) library(knitr) library(tidyselect) library(kableExtra) +library(stringr) options(readr.show_col_types = FALSE) ``` -### Example subset of product-level output of emissions profile. +```{css, echo=FALSE} +@import url('https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@400;700&display=swap'); -```{r, echo=FALSE} -emission_product_example <- product_emission |> - select(all_of(c("companies_id", "country", "emission_profile", "tilt_sector", - "tilt_subsector", "main_activity"))) |> - distinct() |> - mutate(companies_id = ifelse(companies_id == "insecticidal_clownanemonefish", - "heliophobic_clownanemonefish", companies_id)) |> - filter(companies_id %in% c("antimonarchy_canine", "nonphilosophical_llama", - "subdermal_chipmunk", "fascist_maiasaura", - "ironhearted_tarpan", "heliophobic_clownanemonefish", - "subzero_whiteeye")) -``` - -```{r} -kable(emission_product_example |> head(20)) -``` - -### Example subset of product-level output of sector profile. - -```{r, echo=FALSE} -sector_product_example <- product_sector |> - select(all_of(c("companies_id", "country", "sector_profile", "tilt_sector", - "tilt_subsector", "main_activity"))) |> - distinct() |> - mutate(companies_id = ifelse(companies_id == "insecticidal_clownanemonefish", - "heliophobic_clownanemonefish", companies_id)) |> - filter(companies_id %in% c("antimonarchy_canine", "nonphilosophical_llama", - "subdermal_chipmunk", "fascist_maiasaura", - "ironhearted_tarpan", "heliophobic_clownanemonefish", - "subzero_whiteeye")) -``` - -```{r} -kable(sector_product_example |> head(20)) +table { + font-family: 'Roboto Condensed', sans-serif; +} ``` ### Example subset of 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(all_of(c("companies_id", "country", "transition_risk_category", "tilt_sector", - "tilt_subsector", "main_activity"))) |> + select(all_of(c("companies_id", "country", "transition_risk_category", "emission_category", + "sector_category", "tilt_sector", "tilt_subsector", "main_activity"))) |> distinct() |> mutate(companies_id = ifelse(companies_id == "insecticidal_clownanemonefish", "heliophobic_clownanemonefish", companies_id)) |> @@ -75,15 +47,13 @@ transition_risk_product_example <- product_transition_risk |> ``` ```{r} -kable(transition_risk_product_example |> head(20)) +kable(transition_risk_product_example |> head(10)) ``` -### Number of companies for emission, sector, and transition risk profile +### Number of distinct companies ```{r, results='asis'} -cat("Number of companies for emission profile:", n_distinct(emission_product_example$companies_id)) -cat("Number of companies for sector profile:", n_distinct(sector_product_example$companies_id)) -cat("Number of companies for transition risk profile:", n_distinct(transition_risk_product_example$companies_id)) +cat("Number of distinct firms: ", n_distinct(transition_risk_product_example$companies_id)) ``` ### Number of companies that have atleast one product with `emission_profile`, with `sector_profile`, and with `transition_risk_category` @@ -92,20 +62,20 @@ cat("Number of companies for transition risk profile:", n_distinct(transition_ri companies_atleast_one_product_with_profile <- function(data, profile) { result <- data |> select(all_of(c("companies_id", profile))) |> - distinct() |> - filter(!is.na(.data[[profile]])) + filter(!is.na(.data[[profile]])) |> + distinct() n_distinct(result$companies_id) } ``` ```{r, results='asis'} -cat("Number of companies that have atleast one product with `emission_profile`:", companies_atleast_one_product_with_profile(emission_product_example, "emission_profile")) -cat("Number of companies that have atleast one product with `sector_profile`:", companies_atleast_one_product_with_profile(sector_product_example, "sector_profile")) -cat("Number of companies that have atleast one product with `transition_risk_category`:", companies_atleast_one_product_with_profile(transition_risk_product_example, "transition_risk_category")) +cat("Number of firms that have atleast one product with `emission_profile`:", companies_atleast_one_product_with_profile(transition_risk_product_example, "emission_category")) +cat("Number of firms that have atleast one product with `sector_profile`:", companies_atleast_one_product_with_profile(transition_risk_product_example, "sector_category")) +cat("Number of firms that have atleast one product with `transition_risk_category`:", companies_atleast_one_product_with_profile(transition_risk_product_example, "transition_risk_category")) ``` -### Number of companies that have more than one tilt_sectors for emission, sector, and transition risk profile +### Number of companies that have more than one tilt_sectors ```{r} companies_with_multiple_tilt_sectors <- function(data) { @@ -120,12 +90,10 @@ companies_with_multiple_tilt_sectors <- function(data) { ``` ```{r, results='asis'} -cat("Number of companies that have more than one tilt_sectors for emission profile:", companies_with_multiple_tilt_sectors(emission_product_example)) -cat("Number of companies that have more than one tilt_sectors for sector profile:", companies_with_multiple_tilt_sectors(sector_product_example)) -cat("Number of companies that have more than one tilt_sectors for transition risk profile:", companies_with_multiple_tilt_sectors(transition_risk_product_example)) +cat("Number of firms that have more than one tilt_sectors: ", companies_with_multiple_tilt_sectors(transition_risk_product_example)) ``` -### Number of companies that have more than one tilt_subsectors for emission, sector, and transition risk profile +### Number of companies that have more than one tilt_subsectors ```{r} companies_with_multiple_tilt_subsectors <- function(data) { @@ -140,183 +108,127 @@ companies_with_multiple_tilt_subsectors <- function(data) { ``` ```{r, results='asis'} -cat("Number of companies that have more than one tilt_subsectors for emission profile:", companies_with_multiple_tilt_subsectors(emission_product_example)) -cat("Number of companies that have more than one tilt_subsectors for sector profile:", companies_with_multiple_tilt_subsectors(sector_product_example)) -cat("Number of companies that have more than one tilt_subsectors for transition risk profile:", companies_with_multiple_tilt_subsectors(transition_risk_product_example)) +cat("Number of firms that have more than one tilt_subsectors: ", companies_with_multiple_tilt_subsectors(transition_risk_product_example)) ``` -### Number of companies per tilt_sector for emission, sector, and transition risk profile +### Number of companies per tilt_sector ```{r} companies_per_single_benchmark <- function(data, benchmark) { data |> select(all_of(c("companies_id", benchmark))) |> distinct() |> - mutate(companies_count = n_distinct(companies_id, na.rm = TRUE), .by = benchmark) |> + mutate("# of firms" = n_distinct(companies_id, na.rm = TRUE), .by = benchmark) |> select(-all_of(c("companies_id"))) |> distinct() |> + filter(!str_detect(.data[[benchmark]], "NA")) |> arrange(.data[[benchmark]]) } ``` ```{r, warning=FALSE, echo=FALSE} -kable(companies_per_single_benchmark(emission_product_example, "tilt_sector"), align = "lc", caption = "Number of companies per tilt_sector for emission profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:2, width = "3cm") -kable(companies_per_single_benchmark(sector_product_example, "tilt_sector"), align = "lc", caption = "Number of companies per tilt_sector for sector profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:2, width = "3cm") -kable(companies_per_single_benchmark(transition_risk_product_example, "tilt_sector"), align = "lc", caption = "Number of companies per tilt_sector for transition risk profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> +kable(companies_per_single_benchmark(transition_risk_product_example, "tilt_sector"), align = "lc", caption = "# of firms per tilt_sector", escape = F) |> + kable_classic(full_width = F, html_font = "Roboto Condensed") |> column_spec(1:2, width = "3cm") ``` -### Number of companies per tilt_subsector for emission, sector, and transition risk profile +### Number of companies per tilt_subsector ```{r, warning=FALSE, echo=FALSE} -kable(companies_per_single_benchmark(emission_product_example, "tilt_subsector"), align = "lc", caption = "Number of companies per tilt_subsector for emission profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:2, width = "3cm") -kable(companies_per_single_benchmark(sector_product_example, "tilt_subsector"), align = "lc", caption = "Number of companies per tilt_subsector for sector profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:2, width = "3cm") -kable(companies_per_single_benchmark(transition_risk_product_example, "tilt_subsector"), align = "lc", caption = "Number of companies per tilt_subsector for transition risk profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> +kable(companies_per_single_benchmark(transition_risk_product_example, "tilt_subsector"), align = "lc", caption = "# of firms per tilt_subsector", escape = F) |> + kable_classic(full_width = F, html_font = "Roboto Condensed") |> column_spec(1:2, width = "3cm") ``` -### Number of companies per country for emission, sector, and transition risk profile +### Number of companies per country ```{r, warning=FALSE, echo=FALSE} -kable(companies_per_single_benchmark(emission_product_example, "country"), align = "lc", caption = "Number of companies per country for emission profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:2, width = "3cm") -kable(companies_per_single_benchmark(sector_product_example, "country"), align = "lc", caption = "Number of companies per country for sector profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:2, width = "3cm") -kable(companies_per_single_benchmark(transition_risk_product_example, "country"), align = "lc", caption = "Number of companies per country for transition risk profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> +kable(companies_per_single_benchmark(transition_risk_product_example, "country"), align = "lc", caption = "# of firms per country", escape = F) |> + kable_classic(full_width = F, html_font = "Roboto Condensed") |> column_spec(1:2, width = "3cm") ``` -### Number of companies per country and tilt_sector emission, sector, and transition risk profile +### Number of companies per country and tilt_sector ```{r} companies_per_double_benchmark <- function(data, benchmark_first, benchmark_second) { data |> select(all_of(c("companies_id", benchmark_first, benchmark_second))) |> distinct() |> - mutate(companies_count = n_distinct(companies_id, na.rm = TRUE), .by = c(benchmark_first, benchmark_second)) |> + mutate("# of firms" = n_distinct(companies_id, na.rm = TRUE), .by = c(benchmark_first, benchmark_second)) |> select(-all_of(c("companies_id"))) |> distinct() |> + filter(!str_detect(.data[[benchmark_first]], "NA")) |> + filter(!str_detect(.data[[benchmark_second]], "NA")) |> arrange(.data[[benchmark_first]], .data[[benchmark_second]]) } ``` ```{r, warning=FALSE, echo=FALSE} -kable(companies_per_double_benchmark(emission_product_example, "country", "tilt_sector"), align = "lcc", caption = "Number of companies per country and tilt_sector for emission profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:3, width = "3cm") -kable(companies_per_double_benchmark(sector_product_example, "country", "tilt_sector"), align = "lcc", caption = "Number of companies per country and tilt_sector for sector profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:3, width = "3cm") -kable(companies_per_double_benchmark(transition_risk_product_example, "country", "tilt_sector"), align = "lcc", caption = "Number of companies per country and tilt_sector for transition risk profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> +kable(companies_per_double_benchmark(transition_risk_product_example, "country", "tilt_sector"), align = "llc", caption = "# of firms per country and tilt_sector", escape = F) |> + kable_classic(full_width = F, html_font = "Roboto Condensed") |> column_spec(1:3, width = "3cm") ``` -### Number of companies per country and tilt_subsector emission, sector, and transition risk profile +### Number of companies per country and tilt_subsector ```{r, warning=FALSE, echo=FALSE} -kable(companies_per_double_benchmark(emission_product_example, "country", "tilt_subsector"), align = "lcc", caption = "Number of companies per country and tilt_subsector for emission profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:3, width = "3cm") -kable(companies_per_double_benchmark(sector_product_example, "country", "tilt_subsector"), align = "lcc", caption = "Number of companies per country and tilt_subsector for sector profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:3, width = "3cm") -kable(companies_per_double_benchmark(transition_risk_product_example, "country", "tilt_subsector"), align = "lcc", caption = "Number of companies per country and tilt_subsector for transition risk profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> +kable(companies_per_double_benchmark(transition_risk_product_example, "country", "tilt_subsector"), align = "llc", caption = "# of firms per country and tilt_subsector", escape = F) |> + kable_classic(full_width = F, html_font = "Roboto Condensed") |> column_spec(1:3, width = "3cm") ``` -### Number of companies per main_activity for emission, sector, and transition risk profile +### Number of companies per main_activity ```{r, warning=FALSE, echo=FALSE} -kable(companies_per_single_benchmark(emission_product_example, "main_activity"), align = "lc", caption = "Number of companies per main_activity for emission profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:2, width = "3cm") -kable(companies_per_single_benchmark(sector_product_example, "main_activity"), align = "lc", caption = "Number of companies per main_activity for sector profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:2, width = "3cm") -kable(companies_per_single_benchmark(transition_risk_product_example, "main_activity"), align = "lc", caption = "Number of companies per main_activity for transition risk profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> +kable(companies_per_single_benchmark(transition_risk_product_example, "main_activity"), align = "lc", caption = "# of firms per main_activity", escape = F) |> + kable_classic(full_width = F, html_font = "Roboto Condensed") |> column_spec(1:2, width = "3cm") ``` -### Number of companies per main_activity and tilt_sector for emission, sector, and transition risk profile +### Number of companies per main_activity and tilt_sector ```{r, warning=FALSE, echo=FALSE} -kable(companies_per_double_benchmark(emission_product_example, "main_activity", "tilt_sector"), align = "lcc", caption = "Number of companies per main_activity and tilt_sector for emission profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:3, width = "3cm") -kable(companies_per_double_benchmark(sector_product_example, "main_activity", "tilt_sector"), align = "lcc", caption = "Number of companies per main_activity and tilt_sector for sector profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:3, width = "3cm") -kable(companies_per_double_benchmark(transition_risk_product_example, "main_activity", "tilt_sector"), align = "lcc", caption = "Number of companies per main_activity and tilt_sector for transition risk profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> +result <- companies_per_double_benchmark(transition_risk_product_example, "main_activity", "tilt_sector") |> + filter(tilt_sector %in% c("construction", "industry", "land use")) +kable(result, align = "llc", caption = "# of firms per main_activity and tilt_sector", escape = F) |> + kable_classic(full_width = F, html_font = "Roboto Condensed") |> column_spec(1:3, width = "3cm") ``` -### Number of companies per main_activity and tilt_subsector for emission, sector, and transition risk profile +### Number of companies per main_activity and tilt_subsector ```{r, warning=FALSE, echo=FALSE} -kable(companies_per_double_benchmark(emission_product_example, "main_activity", "tilt_subsector"), align = "lcc", caption = "Number of companies per main_activity and tilt_subsector for emission profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:3, width = "3cm") -kable(companies_per_double_benchmark(sector_product_example, "main_activity", "tilt_subsector"), align = "lcc", caption = "Number of companies per main_activity and tilt_subsector for sector profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:3, width = "3cm") -kable(companies_per_double_benchmark(transition_risk_product_example, "main_activity", "tilt_subsector"), align = "lcc", caption = "Number of companies per main_activity and tilt_subsector for transition risk profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> +kable(companies_per_double_benchmark(transition_risk_product_example, "main_activity", "tilt_subsector"), align = "llc", caption = "# of firms per main_activity and tilt_subsector", escape = F) |> + kable_classic(full_width = F, html_font = "Roboto Condensed") |> column_spec(1:3, width = "3cm") ``` -### Number of companies per main_activity and country for emission, sector, and transition risk profile +### Number of companies per main_activity and country ```{r, warning=FALSE, echo=FALSE} -kable(companies_per_double_benchmark(emission_product_example, "main_activity", "country"), align = "lcc", caption = "Number of companies per main_activity and country for emission profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:3, width = "3cm") -kable(companies_per_double_benchmark(sector_product_example, "main_activity", "country"), align = "lcc", caption = "Number of companies per main_activity and country for sector profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:3, width = "3cm") -kable(companies_per_double_benchmark(transition_risk_product_example, "main_activity", "country"), align = "lcc", caption = "Number of companies per main_activity and country for transition risk profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> +kable(companies_per_double_benchmark(transition_risk_product_example, "main_activity", "country"), align = "llc", caption = "# of firms per main_activity and country", escape = F) |> + kable_classic(full_width = F, html_font = "Roboto Condensed") |> column_spec(1:3, width = "3cm") ``` -### Number of companies per main_activity, country, and tilt_sector for emission, sector, and transition risk profile +### Number of companies per main_activity, country, and tilt_sector ```{r, echo=FALSE} companies_per_main_activity_country_tilt_sector <- function(data) { data |> select(all_of(c("companies_id", "main_activity", "country", "tilt_sector"))) |> distinct() |> - mutate(companies_count = n_distinct(companies_id, na.rm = TRUE), .by = c("main_activity", "country", "tilt_sector")) |> + mutate("# of firms" = n_distinct(companies_id, na.rm = TRUE), .by = c("main_activity", "country", "tilt_sector")) |> select(-all_of(c("companies_id"))) |> distinct() |> + filter(!str_detect(tilt_sector, "NA")) |> arrange(main_activity, country, tilt_sector) } ``` ```{r, warning=FALSE, echo=FALSE} -kable(companies_per_main_activity_country_tilt_sector(emission_product_example), align = "lccc", caption = "Number of companies per main_activity, country, and tilt_sector for emission profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:4, width = "3cm") -kable(companies_per_main_activity_country_tilt_sector(sector_product_example), align = "lccc", caption = "Number of companies per main_activity, country, and tilt_sector for sector profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> - column_spec(1:4, width = "3cm") -kable(companies_per_main_activity_country_tilt_sector(transition_risk_product_example), align = "lccc", caption = "Number of companies per main_activity, country, and tilt_sector for transition risk profile", escape = F) |> - kable_classic(full_width = F, html_font = "Cambria") |> +kable(companies_per_main_activity_country_tilt_sector(transition_risk_product_example), align = "lllc", caption = "# of firms per main_activity, country, and tilt_sector", escape = F) |> + kable_classic(full_width = F, html_font = "Roboto Condensed") |> column_spec(1:4, width = "3cm") ```