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

Side-by-side plot of user selected variables across scenarios #84

Merged
merged 25 commits into from
Feb 28, 2024

Conversation

tonnrueter
Copy link
Contributor

@tonnrueter tonnrueter commented Jan 5, 2024

Function generates a facet wrap/grid plot that shows user defined variables side by side for comparison across different scenarios. Solves Improve cs2 climate plots issue. Plot examples can be found in here

@tonnrueter tonnrueter self-assigned this Jan 5, 2024
@tonnrueter tonnrueter changed the title Side=by-side plot of user selected variables across scenarios Side-by-side plot of user selected variables across scenarios Jan 5, 2024
Copy link
Contributor

@fbenke-pik fbenke-pik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the man page for your newly created function as well.

@fbenke-pik
Copy link
Contributor

Currently, using the variables option is not working as expected

data <- readxl::read_xlsx("~/Downloads/ngfs-magicc-data.xlsx")
vars <- c(
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|10.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|16.7th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|17.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|25.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|33.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|5.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|50.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|66.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|67.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|75.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|83.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|83.3th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|90.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|95.0th Percentile"
)

df <- quitte::as.quitte(data)
mip::plotPercentiles(df, variables = vars)

This gives the error

Warning: 'AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|10.0th Percentile' missing in available dataError in mip::plotPercentiles(df, variables = vars) : Provided variable is missing in data

R/plotPercentiles.R Outdated Show resolved Hide resolved
R/plotPercentiles.R Outdated Show resolved Hide resolved
@tonnrueter
Copy link
Contributor Author

tonnrueter commented Jan 8, 2024

Currently, using the variables option is not working as expected

data <- readxl::read_xlsx("~/Downloads/ngfs-magicc-data.xlsx")
vars <- c(
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|10.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|16.7th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|17.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|25.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|33.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|5.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|50.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|66.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|67.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|75.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|83.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|83.3th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|90.0th Percentile",
  "AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|95.0th Percentile"
)

df <- quitte::as.quitte(data)
mip::plotPercentiles(df, variables = vars)

This gives the error

Warning: 'AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3|10.0th Percentile' missing in available dataError in mip::plotPercentiles(df, variables = vars) : Provided variable is missing in data

Try calling plotPercentiles with AR6 climate diagnostics|Net Atmosphere to Land Flux|CO2|MAGICCv7.5.3, ie. the variable prefix without the Percentile suffix.

Also please note that the data as provided by Oliver cannot directly be fed into plotPercentiles. The following pre-processing steps are necessary:

data <- readxl::read_xlsx("~/Downloads/ngfs-magicc-data.xlsx", sheet = "ngfs-magicc-data") %>%
  mutate_at(vars(starts_with(c("1", "2"))), as.double) %>% 
  filter(Variable %in% vars) %>% 
  reshape2::melt(c("Model", "Scenario", "Region", "Variable", "Unit"), variable.name = "period") %>%
  as.quitte()

@fbenke-pik
Copy link
Contributor

#84 (comment)

Ok, so please enhance the description of the variables parameter, so that it is clear what is expected (a list of variables without the percentile fragments)

@@ -0,0 +1,108 @@
#' Comparison plots show 50th percentile of user selected variables as obtained from different scenario runs. If
#' available in the data, ribbon plots will also show the 33th - 67th percentile in a darker color and the 5th – 95th
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you write "if available" (as in: optional), below you say "must be given" (as in: mandatory). Can you clarify?


#' @author Tonn Rueter
#' @param df `quitte` style data frame containing all variables for each scenario. In the quitte data frame all
#' percentiles must be given as individual variables. Manipulate input data frame such that all percentiles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" In the quitte data frame all percentiles must be given as individual variables ..."
Please add an example to avoid misunderstandings.

"Manipulate input data frame ....."
This should not be here, as it is code documentation, but not a specification of the input parameter and therefore nothing a user has to worry about, right?

@fbenke-pik fbenke-pik self-requested a review January 9, 2024 15:39
Copy link
Contributor

@fbenke-pik fbenke-pik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks great, thank you! Now, we have to wait for @orichters approval to be sure that the function works as intended by him.

Copy link
Contributor

@orichters orichters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, I looked at the examples and they look really good, as I hoped for. We could now add that to the climate section of compareScenarios2 (conditional on data availability)? I did not check the code, but trust Falk's assessment here

@fbenke-pik
Copy link
Contributor

fbenke-pik commented Jan 29, 2024

We could now add that to the climate section of compareScenarios2 (conditional on data availability)?

I think this needs to be merged first? remindmodel/remind#1475
Anyways, as soon as you can give us a run that contains these variables, we can extend remind2.

I did not check the code, but trust Falk's assessment here

The code is fine, but some decisions concerning the expected format of the input parameters are debatable (as in: there is no right or wrong given the data we have right now). We probably have to revisit this point once we have a run with actual data.

@tonnrueter tonnrueter merged commit d706e3e into pik-piam:master Feb 28, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants