View source: R/magpie2ggplot2.R
magpie2ggplot2 | R Documentation |
Function for plotting MAgPIE objects with ggplot2
magpie2ggplot2(data,scenario="default",ylab="Value",title=NULL,
xaxis="Year",yaxis="Value",facet_x="Region", facet_y=NULL,
geom="line",stack=F,color="Scenario",fill="Region",
shape=NULL,linetype=NULL,alpha=NULL,labs=NULL,stat=NULL,
text_size=11,hline=NULL,legend_position="right",
scales="fixed",ncol=5,xlim=NULL,ylim=NULL,file=NULL,
scale=NULL, breaks_x=waiver(),breaks_y=waiver(),
xaxis_angle=90,xlab="Year",linewidth=1,pointwidth=2,
color_pal=NULL,bar_width=NULL,show_grid=FALSE,
group="Region",axis_text_col="black",zoom=FALSE,
space="fixed",legend_nrow=NULL,legend_ncol=NULL,
facet_style="default",na.rm=FALSE,
stack_share=FALSE,point_position="identity",
normalize=NULL,...)
data |
MAgPIE object or list of MAgPIE objects or dataframe of MAgPIE object(s); the name of the list entries is used as scenario name in the legend |
scenario |
If the scenario name is stored in the third dimension: position of the entry in the third dimension that contains the scenario name. Default: "default" |
ylab |
y-axis text |
title |
title appering at the top of the plot |
xaxis |
x-axis of the plot, default: "Year" |
yaxis |
y-axis of the plot, default: "Value" |
facet_x |
x-axis facet, default: "Region" |
facet_y |
y-axis facet, default: NULL |
geom |
"line","point","bar", or "area". If "none" only the ggplot base object is returned. |
stack |
stacked bar plot (TRUE) or not (FALSE) |
color |
Dimension to be colored, default: "Scenario" |
fill |
Dimension to be filled in stacked plots, default: NULL |
shape |
Dimension to be shaped, default: NULL |
linetype |
Dimension to differ in linetypes, default: NULL |
alpha |
Dimension to be transparent in stacked plots, default: NULL |
labs |
vector with legend titles for color,fill,shape,alpha,linetype |
stat |
adds statistics (e.g. "sum" or "mean"), default: NULL |
text_size |
text size of axis, legend and title |
hline |
NULL or MAgPIE objects. Adds a horizontal line. |
legend_position |
right (default), left, top, bottom or none |
scales |
fixed (default), free, free_y or free_x; ?facetgrid for details |
ncol |
Number of columns used in facet_wrap function |
xlim |
x axis limits; NULL or vector with limits |
ylim |
y axis limits; NULL or vector with limits |
file |
File name the output should be written to using ggsave |
scale |
scaling of ggplot2 object before saving to file |
breaks_x |
Vector of x-axis breaks, by default ggplot2 takes the decision |
breaks_y |
Vector of y-axis breaks, by default ggplot2 takes the decision |
xaxis_angle |
Angle of xaxis text in degree, default=90 |
xlab |
x-axis text |
linewidth |
linewidth, default=1 |
pointwidth |
pointwidth, default=3 |
color_pal |
vector of colors defining the color palette, if NULL colors are chosen automaticly |
bar_width |
width of bars in geom bar, default value: NULL |
show_grid |
show minor and major grid lines; FALSE (default) or TRUE |
group |
dimension used for grouping; default value: "Region" |
axis_text_col |
color of axis text and ticks; default value: "black" |
zoom |
TRUE zooms the plot according to xlim and ylim, FALSE omits values not the range of xlim and ylim |
space |
fixed (default), free, free_y or free_x; ?facetgrid for details |
legend_nrow |
Number of rows used in legend |
legend_ncol |
Number of columns used in legend |
facet_style |
style of facets, default or paper |
na.rm |
Boolean deciding whether NA values should be filtered out of the data or not. |
stack_share |
stacked bar plot showing shares (TRUE) or absolut values (FALSE) |
point_position |
position of points; "identity" or position_dodge(width = 1) |
normalize |
NULL (default) or year which should be used to normalize the data |
... |
Further options passed to as.ggplot |
ggplot2 object representing one or more MAgPIE objects.
Florian Humpenoeder, David Klein
## Not run:
crop_area_reg <- list()
crop_area_reg[["scenario_name"]] <- croparea("fulldata.gdx")
magpie2ggplot2(crop_area_reg,ylab="10^6 ha",title="Croparea",stack=T,facet_x="Scenario",color=NULL)
## End(Not run)
## Not run:
prices <- list()
prices[["Scenario1"]] <- prices("Scenario1.gdx",crops=c("tece","maiz"))
prices[["Scenario2"]] <- prices("Scenario2.gdx",crops=c("tece","maiz"))
magpie2ggplot2(prices,ylab="US$/ton DM",title="Agricultural prices")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.