pik-piam / mip Goto Github PK
View Code? Open in Web Editor NEWModel intercomparison visualization package
License: Other
Model intercomparison visualization package
License: Other
Quoting @amnmalik: "using mip:: scenTool() on a historical MIF file, and while accessing the "Tables" tab, get this error "
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"?
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
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.
#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')
#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')
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.
Plots using showAreaAndBarPlots
which calls mipArea
and mipBarYearData
can have strange y-axes labels:
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…
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))))
.
Is this
Line 79 in 0070f27
> plotstyle('e', verbosity = 1, out = 'all')
legend color marker linestyle
e emicapregi #A6CEE3 NA
Extend plotstyle()
for partial matching of entities via regular expression to allow for browsing of what's there and what isn't.
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?
- The all new functions with a
scales
argument have"free_y"
as a default.
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.
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?
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.
Check again whether this is fixed with #63 once this is merged.
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)
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.