plotstyle() ignores units -- and anything it considers to be one
Opened this issue · 4 comments
Differentiating entities by unit ("x (y)"
) in plotstyle()
does not work.
mip/inst/extdata/plotstyle.csv
Lines 631 to 636 in 5a7c1cc
> plotstyle(c('Trucks', 'Trucks (<3.5t)', 'Trucks (3.5t-16)', 'Trucks (>16)'))
Trucks Trucks Trucks Trucks
"#ff6a6a" "#ff6a6a" "#ff6a6a" "#ff6a6a"
You might want to replace the parentheses with brackets (Trucks [<3.5t]
) to get that working.
Due to code-quirks, these however work
mip/inst/extdata/plotstyle.csv
Lines 661 to 665 in 5a7c1cc
> plotstyle(c('(0−3.5t)', '(7.5t)', '(40t)', '(26t)', '(18t)'))
(0−3.5t) (7.5t) (40t) (26t) (18t)
"#B0EBEE" "#2893A9" "#172f56" "#25467c" "#325fa4"
But maybe you want to be consistent and change it there, too.
@dklein-pik: The origin of these got wiped by the move from svn to git
mip/inst/extdata/plotstyle.csv
Lines 331 to 336 in 5a7c1cc
and Anastasis isn't around anymore
mip/inst/extdata/plotstyle.csv
Line 585 in 5a7c1cc
> plotstyle(c('Forcing|CO2 (W/m2)', 'Forcing|CH4 (W/m2)', 'Forcing|N2O (W/m2)',
+ 'Forcing|F-Gases (W/m2)', 'Forcing|Aerosol (W/m2)',
+ 'Forcing|Other (W/m2)', 'Emi|GHGtot (Mt CO2-equiv/yr)'))
Forcing|CO2 Forcing|CH4 Forcing|N2O Forcing|F-Gases Forcing|Aerosol Forcing|Other
"#331a00" "#ffe7a0" "#44ba97" "#ff9977" "#6e7700" "#08262f"
Emi|GHGtot
"red"
but plotstyle()
seems to be mostly your thing.
Should I clean those up in ./inst/extdata/plotstyle.csv
? I'm working on an improvement to plotstyle()
and would prefer not to carry over legacy edge cases, but issue a warning for entities with units instead.
@dklein-pik: Can we maybe find a solution for that? The NAVIGATE template contains a variable named Final Energy|Transportation (w/ bunkers)
, and plotting
d <- "/p/projects/remind/modeltests/remind/output/SSP2-NPi-AMT_2024-06-25_16.01.12/REMIND_generic_SSP2-NPi-AMT.mif" %>%
piamInterfaces::generateIIASASubmission(outputFilename = NULL, mapping = "NAVIGATE", generatePlots = FALSE)
d %>% mip::showAreaAndBarPlots(c("Final Energy|Transportation", "Final Energy|Bunkers"), tot = "Final Energy|Transportation (w/ bunkers)", mainReg= "World", yearsBarPlot = c(2030, 2050))
fails with:
<error/rlang_error>
Error in `.rowNamesDF<-`:
! missing values in 'row.names' are not allowed
---
Backtrace:
▆
1. ├─as_tibble(d) %>% ...
2. ├─mip::showAreaAndBarPlots(...)
3. │ └─... %>% ...
4. └─mip::mipArea(., scales = scales, total = is.null(tot), ylab = lcp)
5. ├─ggplot2::scale_fill_manual(...)
6. │ └─ggplot2:::manual_scale(aesthetics, values, breaks, ..., na.value = na.value)
7. │ └─rlang::is_missing(values)
8. └─mip::plotstyle(levels(x[[dimToStack]]))
9. ├─base::`row.names<-`(`*tmp*`, value = uqEntity)
10. └─base::`row.names<-.data.frame`(`*tmp*`, value = uqEntity)
11. └─base::`.rowNamesDF<-`(x, value = value)
The reason is that mip::plotstyle("Final Energy|Transportation (w/ bunkers)")
returns
Final Energy|Transportation
"#000000"
and the mipArea script is not able to match the color to the variable name.
Removing this line would do it, I guess, but I wonder whether there is a reason for the existence of this line…
Removing this line would do it, I guess, but I wonder whether there is a reason for the existence of this line…
Plotting magpie
objects, which have units in parentheses attached to their variable names.
Removing this line would do it, I guess, but I wonder whether there is a reason for the existence of this line…
Plotting
magpie
objects, which have units in parentheses attached to their variable names.
But most (all?) of the mip functions convert with as.quitte
first, and this code in as.quitte.magpie separates variables and units anyway. I also doubt that it would actually work without that step, given that the code for mipArea
obviously does not work if something that plotstyle guesses to be a unit is still around.
I did not say it is a good reason.