-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add modes for the emission profile bar plot without financial data (#134
) * added modes arg for bar plot * refactored function + built readme file * tidy style change vignette * added FIXME * figure update * error in vignette * added tiltIndicatorAfter * adapted Rmd file to work with tiltIndicatorAfter * styled * udpated readme * change DESCRIPTION * added NEWS.md * news.md modified * Update DESCRIPTION Co-authored-by: Mauro Lepore <[email protected]> * Update DESCRIPTION Co-authored-by: Mauro Lepore <[email protected]> * Update R/bar_plot_emission_profile.R Co-authored-by: Mauro Lepore <[email protected]> * added modes() * changed to Imports --------- Co-authored-by: Mauro Lepore <[email protected]>
- Loading branch information
1 parent
9bd0208
commit a931511
Showing
11 changed files
with
149 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit --> | ||
|
||
# tiltPlot 0.0.0.9002 (2024-06-04) | ||
|
||
* `bar_plot_emission_profile()` has now modes that the user can choose from (#134). | ||
|
||
# tiltPlot 0.0.0.9001 (2023-06-27) | ||
|
||
* New `plot_sankey()` and `toy_data`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,86 @@ | ||
test_that("returns an object of the expected class", { | ||
data <- example_without_financial() | ||
plot <- bar_plot_emission_profile(data, benchmarks()) | ||
plot <- bar_plot_emission_profile(data, benchmarks(), mode = "equal_weight") | ||
expect_s3_class(plot, "ggplot") | ||
}) | ||
|
||
test_that("returns correct risk category values", { | ||
test_that("returns correct risk category values for equal weight mode", { | ||
data <- example_without_financial(!!aka("risk_category") := risk_category_levels()) | ||
plot <- bar_plot_emission_profile(data, benchmarks()) | ||
risk_categories <- levels(plot |> plot_data("risk_category_var")) | ||
data <- prepare_bar_plot_emission_profile(data, benchmarks(), "equal_weight") | ||
risk_categories <- levels(data$risk_category_var) | ||
expected_risk_categories <- risk_category_levels() | ||
expect_true(setequal(risk_categories, expected_risk_categories)) | ||
}) | ||
|
||
test_that("returns correct benchmarks values", { | ||
test_that("returns correct risk category values for best case mode", { | ||
data <- example_without_financial(!!aka("risk_category") := risk_category_levels()) | ||
data <- prepare_bar_plot_emission_profile(data, benchmarks(), "best_case") | ||
risk_categories <- levels(data$risk_category_var) | ||
expected_risk_categories <- risk_category_levels() | ||
expect_true(setequal(risk_categories, expected_risk_categories)) | ||
}) | ||
|
||
test_that("returns correct risk category values for worst_case mode", { | ||
data <- example_without_financial(!!aka("risk_category") := risk_category_levels()) | ||
data <- prepare_bar_plot_emission_profile(data, benchmarks(), "worst_case") | ||
risk_categories <- levels(data$risk_category_var) | ||
expected_risk_categories <- risk_category_levels() | ||
expect_true(setequal(risk_categories, expected_risk_categories)) | ||
}) | ||
|
||
test_that("returns correct benchmarks values for equal weight mode", { | ||
data <- example_without_financial() | ||
data <- prepare_bar_plot_emission_profile(data, benchmarks(), "equal_weight") | ||
benchmarks <- unique(data$benchmark) | ||
expected_benchmarks <- example_without_financial() |> | ||
pull(benchmark) |> | ||
unique() | ||
expect_true(all(benchmarks %in% expected_benchmarks)) | ||
}) | ||
|
||
test_that("returns correct benchmarks values for best case mode", { | ||
data <- example_without_financial() | ||
plot <- bar_plot_emission_profile(data, benchmarks()) | ||
benchmarks <- unique(plot |> plot_data("benchmark")) | ||
expected_benchmarks <- data |> | ||
data <- prepare_bar_plot_emission_profile(data, benchmarks(), "best_case") | ||
benchmarks <- unique(data$benchmark) | ||
expected_benchmarks <- example_without_financial() |> | ||
pull(benchmark) |> | ||
unique() | ||
expect_true(all(benchmarks %in% expected_benchmarks)) | ||
}) | ||
|
||
test_that("calculated proportions are less or equal to 1", { | ||
test_that("returns correct benchmarks values for worst case mode", { | ||
data <- example_without_financial() | ||
plot <- bar_plot_emission_profile(data, benchmarks()) | ||
proportions <- plot |> plot_data("proportion") | ||
expect_true(proportions >= 0 & proportions <= 1) | ||
data <- prepare_bar_plot_emission_profile(data, benchmarks(), "worst_case") | ||
benchmarks <- unique(data$benchmark) | ||
expected_benchmarks <- example_without_financial() |> | ||
pull(benchmark) |> | ||
unique() | ||
expect_true(all(benchmarks %in% expected_benchmarks)) | ||
}) | ||
|
||
test_that("proportions are less or equal to 1 for equal weight mode", { | ||
data <- example_without_financial() | ||
data <- data |> | ||
prepare_bar_plot_emission_profile(benchmarks(), mode = "equal_weight") | ||
|
||
proportions <- data$proportion | ||
expect_true(all(proportions >= 0 & proportions <= 1)) | ||
}) | ||
|
||
test_that("proportions are less or equal to 1 for best case mode", { | ||
data <- example_without_financial() | ||
data <- data |> | ||
prepare_bar_plot_emission_profile(benchmarks(), mode = "best_case") | ||
|
||
proportions <- data$proportion | ||
expect_true(all(proportions >= 0 & proportions <= 1)) | ||
}) | ||
|
||
test_that("proportions are less or equal to 1 for worst case mode", { | ||
data <- example_without_financial() | ||
data <- data |> | ||
prepare_bar_plot_emission_profile(benchmarks(), mode = "worst_case") | ||
|
||
proportions <- data$proportion | ||
expect_true(all(proportions >= 0 & proportions <= 1)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters