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

Add qplots for techmix and emission intensity #364

Merged
merged 23 commits into from
Jun 25, 2021
Merged

Add qplots for techmix and emission intensity #364

merged 23 commits into from
Jun 25, 2021

Conversation

MonikaFu
Copy link
Collaborator

In this PR I add quick plots for:

  • techmix
  • emission intensity

Also - some refactoring is performed.

@MonikaFu MonikaFu marked this pull request as draft June 25, 2021 15:02
@MonikaFu MonikaFu marked this pull request as ready for review June 25, 2021 18:28
"The `technology_share` values are plotted for extreme years.
Do you want to plot different years? E.g. filter the data with:\\
`subset(data, year %in% c(2020, 2030))`."
))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure if this is not an overkill.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you intend to inform both when span_5yr = TRUE and span_5yr = FALSE?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we enhance the message with the user's data? E.g.

  • replacing the literal "extreeme years" with the actual years we are plotting.
  • replacing data with the symbol the user used to name their data -- see how by searching for calls similar to .data <- deparse_1(substitute(data, env = env))
  • replacing "... c(2020, 2030) ..." with "... {range(data$year, na.rm = TRUE)} ..."

Copy link
Contributor

Choose a reason for hiding this comment

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

For messages I usually like the "-ing" form. Also, from this message I'm not sure why it's important for me (a user) to know this informaiton. If I understand correctly the issue we want the user to be aware is that they'll get plot for a range of years that is different than the standard 5-years span defined by PACTA, right?

If so, here is my suggestion:

span <- diff(range(data$year, na.rm = TRUE))
if (span > 5L) {
  inform(glue("Plotting `technology_share` values for more than the 5 years span defined by PACTA".))
}

if (span < 5L) {
  ... Plotting ... for less than the 5 years defined by PACTA ...
}

R/plot_techmix.R Outdated
data %>%
select(.data$technology, .data$label_tech) %>%
unique(),
by = "technology")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need the label_tech from 'data'. If there is any cleaner way to get it - I'd like to know!

Copy link
Contributor

@maurolepore maurolepore left a comment

Choose a reason for hiding this comment

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

LGTM. I think all my comments are NB.

R/plot_emission_intensity.R Show resolved Hide resolved
R/plot_emission_intensity.R Outdated Show resolved Hide resolved
R/plot_emission_intensity.R Show resolved Hide resolved
R/plot_techmix.R Show resolved Hide resolved
"The `technology_share` values are plotted for extreme years.
Do you want to plot different years? E.g. filter the data with:\\
`subset(data, year %in% c(2020, 2030))`."
))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you intend to inform both when span_5yr = TRUE and span_5yr = FALSE?


---

[1] "Tons of CO2 per ton"
Copy link
Contributor

Choose a reason for hiding this comment

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

Tons of Co2 per ton <of what?>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question! We need a unit!

@@ -0,0 +1,4 @@
# Has the title as expected

Current and future technology mix for the Power sector
Copy link
Contributor

Choose a reason for hiding this comment

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

The letter case seems odd: It's sentence case until we reach "Power". A more conventional way to emphasize a word is with italics or "quotes", or simply by making it take the emphasis position of a sentence -- the position right next to a colon, semi-colon, or period.

Suggestions:

  • Current and future technology mix for the power sector
  • Current and future technology mix for the "power" sector
  • Current and future technology mix for the sector power.

expect_equal(pretty, metrics)
metrics <- unique(p$data$label)
ugly <- c("projected", "corporate_economy")
expect_equal(ugly, metrics)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to pass ugly to the expected argument of expect_equal(), i.e.

expect_equal(actual = metrics, expected = ugly)

This will result in clearer failure messages. See how actual and expected are mixed up here

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I did this wrong in many places :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😆 alright will try to amend

expect_equal(p$labels$x, "Year")
expect_snapshot_output(p$labels$x)

expect_match(p$labels$y, "[Tt]ons of CO2 per ton")
Copy link
Contributor

Choose a reason for hiding this comment

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

I often use [Aa] because I want to ignore the letter case of A. But in this case we likely want this test to fail if "A" becomes "a", right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, true. In this case it is not the right way to do it

)
p <- qplot_techmix(data)

expect_true(max(p$data$year) - min(p$data$year) <= 5)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need na.rm = TRUE? We haven't tested the package when data has NA, so I fear we'll see bugs where we call min(), max(), range(), sum(), and every other function that includes na.rm.

@MonikaFu MonikaFu merged commit 0169660 into develop Jun 25, 2021
@MonikaFu MonikaFu deleted the add-qplots branch June 25, 2021 21:31
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.

2 participants