Code Monkey home page Code Monkey logo

mip's People

Contributors

0umfhxcvx5j7joaohfss5mncnistjj6q avatar abhimishr avatar bodirsky avatar cchrisgong avatar chroetz avatar corneliaauerpik avatar dklein-pik avatar fbenke-pik avatar flohump avatar giannou avatar jmuessel avatar johannah-pik avatar laviniabaumstark avatar mishkos avatar moulai avatar orichters avatar pfuehrlich-pik avatar piklev avatar pre-commit-ci[bot] avatar renato-rodrigues avatar ricardarosemann avatar robertpietzcker avatar robinhasse avatar sosorior avatar stephnwirth avatar tonnrueter avatar tscheypidi avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

mip's Issues

plotstyle(..., plot = TRUE) is broken

entities <- c('AFR', 'AAA', 'AFR', 'UNKNOWN_ELEMENT2')
plotstyle(entities, plot = TRUE)

gives
Error: StatBin requires a continuous x variable: the x variable is discrete. Perhaps you want stat="count"?

plotstyle() ignores units -- and anything it considers to be one

Differentiating entities by unit ("x (y)") in plotstyle() does not work.

@johannah-pik

Trucks;Trucks;#ff6a6a;;
ICE;ICE;#8c8c8c;;
NG;NG;#d11141;;
Trucks (<3.5t);Trucks (<3.5t);#ff7f50;;
Trucks (3.5t-16);Trucks (3.5t-16);#8b0000;;
Trucks (>16) ;Trucks (>16) ;#fa8072;;

> 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

(0−3.5t);(0−3.5t);#B0EBEE;;
(7.5t);(7.5t);#2893A9;;
(40t);(40t);#172f56;;
(26t);(26t);#25467c;;
(18t);(18t);#325fa4;;

> 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

Forcing|CO2 (W/m2);CO2;#331a00;;
Forcing|CH4 (W/m2);CH4;#ffe7a0;;
Forcing|N2O (W/m2);N2O;#44ba97;;
Forcing|F-Gases (W/m2);F-Gases;#ff9977;;
Forcing|Aerosol (W/m2);Aerosol;#6e7700;;
Forcing|Other (W/m2);Other;#08262f;;

and Anastasis isn't around anymore
Emi|GHGtot (Mt CO2-equiv/yr);GHG Emissions (Mt CO2-equiv/yr);red;;

> 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.

#68 breaks historical legends in mip plots (and therefore compare scenarios)

#66 works

devtools::install_github('pik-piam/mip', 'c64c7ed')
library(mip)
library(tidyverse)

d <- tribble(
  ~model,   ~scenario,      ~region,   ~variable,   ~unit,   ~period,   ~value,
  'foo',    'foo',          'foo',     'foo',       'foo',   1,         1,
  'foo',    'foo',          'foo',     'foo',       'foo',   2,         2,
  'bar',    'historical',   'foo',     'foo',       'foo',   1,         1,
  'bar',    'historical',   'foo',     'foo',       'foo',   2,         4)

showLinePlots(d, 'foo', mainReg = 'foo')

image

#68 does not

devtools::install_github('pik-piam/mip', 'b8a98a7')
library(mip)
library(tidyverse)

d <- tribble(
  ~model,   ~scenario,      ~region,   ~variable,   ~unit,   ~period,   ~value,
  'foo',    'foo',          'foo',     'foo',       'foo',   1,         1,
  'foo',    'foo',          'foo',     'foo',       'foo',   2,         2,
  'bar',    'historical',   'foo',     'foo',       'foo',   1,         1,
  'bar',    'historical',   'foo',     'foo',       'foo',   2,         4)

showLinePlots(d, 'foo', mainReg = 'foo')

image

mipBarYearData() breaks on non-default scenario order

When called through output.R -> compareScenarios.R with non-default order of scenarios (e.g. 10,8 instead of 8,10) mipBarYearData() does not produce any plots, but throws an error

## Error: Insufficient values in manual scale. 2 needed but only 1 provided.

Confusing ylab in mipArea / mipBarYearData / showAreaAndBarPlots

Plots using showAreaAndBarPlots which calls mipArea and mipBarYearData can have strange y-axes labels:

mip_plots

The variables involved are:

Agricultural Demand|Crops|Energy|1st generation
Agricultural Demand|Crops|Energy|2nd generation

On the left page, showAreaAndBarPlots just uses longestCommonPrefix and the generation part is dropped completely.

On the right page, this code in mipArea turns it into:

varnames <- c("Agricultural Demand|Crops|Energy|1st generation", "Agricultural Demand|Crops|Energy|2nd generation")
mip:::shorten_legend(varnames, identical_only = TRUE)
[1] "1st" "2nd"
attr(,"front")
[1] "Agricultural Demand|Crops|Energy|"
attr(,"back")
[1] " generation"

which leads to an y-axis label

Agricultural Demand|Crops|Energy generation

which reads as if it was "Energy generation" which is very confusing. The legend just states 1st and 2nd. Why is the back attribute just pasted to the front, that seems weird to me.

In any case, I would be pleased if that could be harmonized, either by leaving the back part attached to the legend label, or by writing something like Agricultural Demand|Crops|Energy|… generation into the ylabel.

I can implement that, but I have no overview on how these functions are used and why it was implemented as such. Asking @LaviniaBaumstark, @dklein-pik, @tscheypidi

Plot functions handle color selection differently

mipArea() uses plotstyle(as.character(unique(x[[dimToStack]]))), mipBarYearData() uses plotstyle(levels(x$variable)) to obtain colors for plotted objects. This may lead to inconsistent assignment of colors, in particular when x$variable and x[[dimToStack]] are factors with levels not in plotstyle.csv: Compare plotstyle(levels(factor(3:1))) and plotstyle(as.character(unique(factor(3:1)))).

mipLineHistorical() ignores linetype.dim

Works:

library(mip)

mipLineHistorical(x = mip_example_data[,,'REMIND', pmatch = TRUE],
                  color.dim = 'variable') +
  theme(legend.position = 'none')

works

Does not work:

mipLineHistorical(x = mip_example_data[,,'REMIND', pmatch = TRUE],
                  linetype.dim = 'variable') +
  theme(legend.position = 'none')

doesnt_work

Possible improvements in plotPercentiles

  • not urgent at all, just some suggestions
  • somehow an explanation what the ribbons mean would be awesome. No idea how this should best be done.
  • harmonize background to a white one, similar to all other plots from this library. Adding this to line 91 did not seem to work, maybe I missed something.

image

droplevels in mipArea etc. drop deletedinfo attribute

therefore, it does not show up anymore in the legend title

To reproduce:

q <- dplyr::filter(quitte::quitte_example_dataAR6, model == "GCAM")
q$identifier <- mip::identifierModelScen(q)
message(attr(q$identifier, "deletedinfo"))
q <- droplevels(q)
message(attr(q$identifier, "deletedinfo"))

That is for me a rather unexpected behavior and I would like to know how I can attach some piece of information here to a quitte object such that it is still available after going through droplevels in mip plotting scripts.

It seems to me that replacing droplevels(q) by droplevels(q, except = intersect(names(q), "identifier")) everywhere in the relevant mip functions should do the job. Any objections?

Extend Y-Scales to Zero?

  • The all new functions with a scales argument have "free_y" as a default.

pik-piam/remind2/#182

Maybe it is worthwhile to extend y-axes to zero by default, or at least give the option to do so (using ggplot2::expand_limits(). It makes judging relative changes easier. @robertpietzcker might have feelings on this topic, too.

lack of color in some plots

Dear colleagues, I have a strange bug. Using piamInterfaces::plotIntercomparison which calls mip::showLinePlots, I get the following document, which has nice and colorful plots, except for the Nationally Determined Contributions (NDCs) scenario. Anyone an idea, why?

image

Bug and fix in validationpdf.R: PDF may not be generated correctly if "%" in the image title

On line 246, the validationpdf function tried to add a tex_caption to the figure.

swfigure(sw, print, p, tex_caption = preptitle(getNames(m$x)[s]), 
        sw_option = "width=10,height=2")

The function preptitle was called to generate the title from the origin name of the figure.

preptitle <- function(x) {
    x <- sub("\\.([^\\.]*)$", " (\\1)", x)
    x <- sub(".", " ", x, fixed = TRUE)
    x <- sub(" historical", "", x, fixed = TRUE)
    x <- gsub(".", " | ", x, fixed = TRUE)
    return(x)
  }

However, if there are "%" characters in the name of the figure, the pdf would not be generated successfully due to the grammar error in the generated tex file.

For example:
preptitle will generate a caption like "MAgPIE default | Agricultural Research Intensity (% of Total GDP)".
Then swfigure will add this line to the tex file: \caption{MAgPIE default | Agricultural Research Intensity (% of Total GDP)}.
It is here that the problem arises! The "%" in the caption should be preceded by a "", otherwise "% of Total GDP..." will be recognized as a latex command, resulting in an error when compiling to PDF.
This latex command is correct instead: \caption{MAgPIE default | Agricultural Research Intensity (\% of Total GDP)}

The possible solution:
In preptitle function, replace the "%" in the figure name with "percent" (or other string).
Also, I think there will be more elegant and general solutions.

The updated function may looks like:

preptitle <- function(x) {
    x <- sub("\\.([^\\.]*)$", " (\\1)", x)
    x <- sub(".", " ", x, fixed = TRUE)
    x <- sub(" historical", "", x, fixed = TRUE)
    x <- gsub(".", " | ", x, fixed = TRUE)
    x <- gsub("%", "percent", x, fixed = TRUE)
    return(x)
  }

Thank you for providing such a good data analysis tool as mip. Hope this bug can be resolved.

@pfuehrlich-pik

plotstyle() colours for PE (possibly others)

I find the colours plotstyle() returns for PE carriers … odd.

mip::plotstyle(c('PE|Coal', 
                 'PE|Oil', 
                 'PE|Gas', 
                 'PE|Nuclear', 
                 'PE|Hydro', 
                 'PE|Biomass', 
                 'PE|Geothermal', 
                 'PE|Solar', 
                 'PE|Wind'),
               plot = TRUE)

mip_plotstyles_PE
Wouldn't it be worthwhile to change that to something more easily associated with the energy carriers in question? I think we were using different colours before.

Include different options for region color palette

Depending on the use case, different color palettes are desired for the REMIND regions.
The new region colors from this PR are optimized for distinguishability (e.g. for the REMIND validation).
For publications, grouped colors for like-wise regions could be better.

Here is a proposal from Nico for a grouped color palette, that could be implemented as an alternative choice:

OECD regions
plotstyle.add("EUR", "EU", rgb(0.0, 0.0, 0.99, 1), marker = 23, replace = TRUE )
plotstyle.add("NEU", "Other Europe", rgb(0.0, 0.0, 0.65, 1), marker = 9, replace = TRUE )
plotstyle.add("USA", "USA", rgb(0.5, 0.5, 0.99, 1), marker = 10, replace = TRUE )
plotstyle.add("JPN", "Japan", rgb(0.0, 0.5, 0.99, 1), marker = 13, replace = TRUE )
plotstyle.add("CAZ", "Can, Aus, NZ", rgb(0.3, 0.3, 0.8, 1), marker = 17, replace = TRUE )

Regions with developing and Emerging markets
plotstyle.add("CHA", "China", rgb(0.3, 0.99, 0.3, 1), marker = 19, replace = TRUE )
plotstyle.add("IND", "India", rgb(0.3, 0.65, 0.3, 1), marker = 8, replace = TRUE )
plotstyle.add("OAS", "Other Asia", rgb(0.6, 0.99, 0.0, 1), marker = 11, replace = TRUE )
plotstyle.add("SSA", "Sub-Sahra Africa", rgb(0.5, 0.0, 0.99, 1), marker = 15, replace = TRUE )
plotstyle.add("MEA", "Middle East & N. Africa", rgb(0.7, 0.2, 0.99, 1), marker = 17, replace = TRUE )
plotstyle.add("LAM", "Latin America", rgb(0.9, 0.6, 0.5, 1), marker = 12, replace = TRUE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.