Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot_trajectory should correctly label corporate_economy as "Corporate Economy" and projected as "Portfolio" #172

Closed
jdhoffa opened this issue May 26, 2021 · 4 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@jdhoffa
Copy link
Member

jdhoffa commented May 26, 2021

IMPORTANT: The reprex above does not actually highlight the issue.
Due to a bug in r2dii.plot.static, the labels for "Corporate Economy" and "Projected" are swapped, causing terrible confusion.

The "Corporate Economy" in this case starts at 1 and ends at 1.55 in both plots, as expected.

Originally posted by @jdhoffa in https://github.com/2DegreesInvesting/r2dii.analysis/issues/269#issuecomment-848619268

@jdhoffa
Copy link
Member Author

jdhoffa commented May 26, 2021

See reprex below:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(r2dii.plot.static)

out1_trajectory <- tibble::tribble(
  ~year, ~metric_type,             ~metric, ~value,     ~technology,
  2020L,  "portfolio",         "projected",      1, "renewablescap",
  2020L,   "scenario",              "b2ds",      1, "renewablescap",
  2020L,   "scenario",               "nps",      1, "renewablescap",
  2020L,   "scenario",               "sds",      1, "renewablescap",
  2025L,  "portfolio",         "projected",    1.1, "renewablescap",
  2025L,   "scenario",              "b2ds",    1.3, "renewablescap",
  2025L,   "scenario",               "nps",    1.1, "renewablescap",
  2025L,   "scenario",               "sds",    1.2, "renewablescap",
  2020L,  "benchmark", "corporate_economy",      1, "renewablescap",
  2025L,  "benchmark", "corporate_economy",   1.55, "renewablescap"
)

scenario_specs <- tibble(
  scenario = c("b2ds", "sds", "nps", "worse"),
  color = c("#9CAB7C", "#FFFFCC", "#FDE291", "#E07B73"),
  label = c("B2DS", "SDS", "NPS", "worse")
)

main_line_metric <- tibble(
  metric = "projected",
  label = "Portfolio"
)

additional_line_metrics <- tibble(
  metric = "corporate_economy",
  label = "Corporate Economy"
)

# notice here that the final value for "projected" is 1.1, and 
# "corporate_economy" is 1.55
out1_trajectory %>% 
  filter(year == 2025) %>% 
  filter(metric %in% c("projected", "corporate_economy"))
#> # A tibble: 2 x 5
#>    year metric_type metric            value technology   
#>   <int> <chr>       <chr>             <dbl> <chr>        
#> 1  2025 portfolio   projected          1.1  renewablescap
#> 2  2025 benchmark   corporate_economy  1.55 renewablescap


# however in this plot, we can see that the portfolio seems to end at 1.55, and 
# corporate_economy at 1.1
plot_trajectory(
  out1_trajectory,
  scenario_specs_good_to_bad = scenario_specs,
  main_line_metric = main_line_metric,
  additional_line_metrics = additional_line_metrics
)

Created on 2021-05-26 by the reprex package (v2.0.0)

@jdhoffa jdhoffa changed the title Labels for "Corporate Economy" and "Projected" seem to be swapped plot_trajectory should correctly label corporate_economy as "Corporate Economy" and projected as "Portfolio" May 26, 2021
@jdhoffa jdhoffa added the bug an unexpected problem or unintended behavior label May 26, 2021
@MonikaFu
Copy link
Collaborator

MonikaFu commented Jun 1, 2021

@jdhoffa - with the new version of the plot_trajectory function (with annotations) this issue should be solved. Can you confirm?

@jdhoffa
Copy link
Member Author

jdhoffa commented Jun 2, 2021

It seems like it is solved!!
For your reference, the following reprex was generated using the latest version of the package:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(r2dii.plot)

out1_trajectory <- tibble::tribble(
  ~year, ~metric_type,             ~metric, ~value,     ~technology,
  2020L,  "portfolio",         "projected",      1, "renewablescap",
  2020L,   "scenario",              "b2ds",      1, "renewablescap",
  2020L,   "scenario",               "nps",      1, "renewablescap",
  2020L,   "scenario",               "sds",      1, "renewablescap",
  2025L,  "portfolio",         "projected",    1.1, "renewablescap",
  2025L,   "scenario",              "b2ds",    1.3, "renewablescap",
  2025L,   "scenario",               "nps",    1.1, "renewablescap",
  2025L,   "scenario",               "sds",    1.2, "renewablescap",
  2020L,  "benchmark", "corporate_economy",      1, "renewablescap",
  2025L,  "benchmark", "corporate_economy",   1.55, "renewablescap"
)

scenario_specs <- tibble(
  scenario = c("b2ds", "sds", "nps"),
  label = c("B2DS", "SDS", "NPS")
)

main_line_metric <- tibble(
  metric = "projected",
  label = "Portfolio"
)

additional_line_metrics <- tibble(
  metric = "corporate_economy",
  label = "Corporate Economy"
)

# notice here that the final value for "projected" is 1.1, and 
# "corporate_economy" is 1.55
out1_trajectory %>% 
  filter(year == 2025) %>% 
  filter(metric %in% c("projected", "corporate_economy"))
#> # A tibble: 2 x 5
#>    year metric_type metric            value technology   
#>   <int> <chr>       <chr>             <dbl> <chr>        
#> 1  2025 portfolio   projected          1.1  renewablescap
#> 2  2025 benchmark   corporate_economy  1.55 renewablescap

# however in this plot, we can see that the portfolio seems to end at 1.55, and 
# corporate_economy at 1.1
plot_trajectory(
  out1_trajectory,
  scenario_specs_good_to_bad = scenario_specs,
  main_line_metric = main_line_metric,
  additional_line_metrics = additional_line_metrics
)

Created on 2021-06-02 by the reprex package (v2.0.0)

@jdhoffa jdhoffa closed this as completed Jun 2, 2021
@MonikaFu
Copy link
Collaborator

MonikaFu commented Jun 2, 2021

@jdhoffa great! Although I see another problem of annotations overlap here since portfolio overlaps with scenario:/ I'll put it in a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants