gramm cheat sheet

gramm cheat sheet

Every method of gramm with its options, defaults and accepted values. A gramm figure is built in steps:

  1. g = gramm(…)data and groups
  2. facet_grid()subplots
  3. geom_ / stat_layers
  4. set_ optionsappearance
  5. draw()the figure
  6. update()more layers
  7. export()to a file

Layers: raw data, statistics and reference lines and shapes. Steps 2 to 4 can come in any order.

Constructor Object creation, first step

g = gramm( Constructor for the class: creates a gramm object with the data to plot

'x'Data plotted as abscissa, or used for histograms/densities. 1D array or cellstr of length N, or for repeated measurements a 1D array of length M, or a matrix/cell with the same size as y
'y'Data plotted as ordinate. 1D array of length N, or for repeated measurements a N x M matrix or N x 1 cell of arrays (one curve per row/cell)
'ymin'Lower bound of y intervals (absolute), same format as y, see geom_interval()
'ymax'Upper bound of y intervals (absolute), same format as y
'z'Data plotted along z, same format as y
'label'Label text, cellstr of length N, see geom_label()
'color'Grouping variable for colors (hue), or continuous color data (see set_continuous_color())
'lightness'Grouping variable for color lightness
'group'Grouping variable without visual change (e.g. one line per subject)
'linestyle'Grouping variable for line styles
'size'Grouping variable for line/point sizes
'marker'Grouping variable for point shapes
'subset'Logical array of length N selecting the data to plot
'row'Grouping variable for rows of subplots, same as facet_grid()
'column'Grouping variable for columns of subplots, same as facet_grid()
'fig'Grouping variable for separate figures, same as fig()
More

Example syntax: gramm_object=gramm('x',x_variable,'y',y_variable,'color',color_variable) The data can be given in two layouts:

One row per observation: x, y and the grouping variables are 1D arrays of the same length N (like the columns of a table). Points with the same grouping values form a group, e.g. a line for geom_line() or a summary for stat_summary().

One row per repeated measurement (trajectories, time series...): y is a N x M matrix, or a N x 1 cell of arrays (possibly of different lengths), each row/cell being one curve. x is then a 1D array of length M shared by all curves, or a matrix/cell with the same size as y. The grouping variables still have one value per row (length N), so each curve gets the color, marker... of its row.

Grouping variables (color, lightness, row, column...) represent categories, and can be numerical arrays, cellstr, string, categorical, datetime or duration arrays. Categorical arrays are ordered by their categories, dates and durations chronologically (see set_order_options()). x and y (and ymin, ymax) can also be datetime or duration arrays, which are displayed natively on the axes.

Examples: Broken axis · Custom layouts · Marginal histograms · +28

Subplots and figures Method calls, any order

g.facet_grid( Create subplots according to factors for rows and columns

rowVariable separating data by rows of subplots, 1D numerical array or cellstr of length N
colVariable separating data by columns of subplots, 1D numerical array or cellstr of length N
'scale'Axis limits shared between subplots
'fixed'same x and y limits on all subplots
'free_x'same y limits on all subplots, x limits adjusted to the data of each column
'free_y'same x limits on all subplots, y limits adjusted to the data of each row
'free'x limits per column, y limits per row
'independent'independent limits on each subplot (forces 'force_ticks')
'space'Subplot sizes. Used with free scales, so that one x (or y) unit has the same length in all subplots
'fixed'all subplots have the same size
'free_x'column widths proportional to their x range (needs 'scale' 'free_x' or 'free')
'free_y'row heights proportional to their y range (needs 'scale' 'free_y' or 'free')
'free'both (needs 'scale' 'free')
'force_ticks'falseShow tick labels on all subplots
'column_labels'trueLabel the columns of subplots
'row_labels'trueLabel the rows of subplots
More

Example syntax (default arguments): gramm_object.facet_grid(row_variable,column_variable,'scale','fixed') To separate data by rows or columns of subplots only, set the other argument to [] (empty array).

Examples: Broken axis · Post-draw customization · Superimposed plots · +9

g.facet_wrap( Create subplots according to one factor, with wrap

colVariable separating data by subplots, 1D numerical array or cellstr of length N
'ncols'4Number of columns after which a new row of subplots is created
'scale'Axis limits shared between subplots, same as in facet_grid()
'fixed' 'free_x' 'free_y' 'free' 'independent'
'force_ticks'falseShow tick labels on all subplots
'column_labels'trueLabel the subplots
More

Example syntax (default arguments): gramm_object.facet_wrap(variable,'ncols',4,'scale','fixed') Similar to facet_grid() with a single variable: subplots are arranged by column, wrapping around to the next row after 'ncols' columns. There is no 'space' option.

Examples: Dates and durations · Polar plots · Wrap (one-to-many)

g.fig( Create separate figures according to one factor

figVariable separating data by figures, 1D numerical array or cellstr of length N. For each unique value, a new figure is created with the corresponding data
More

Example syntax: gramm_object.fig(variable) Useful when facet_ generates too crowded figures. Warning: the generated gramm figures are independent: no common legend, axis limits, etc.

Raw data geom_ method calls, any order

g.geom_point( Display data as points

'dodge'0Spacing between points of different colors within an unique x value
'alpha'1Transparency of points, from 0 (transparent) to 1 (opaque)
More

Example syntax: gramm_object.geom_point('dodge',0,'alpha',1) Supports color, lightness, marker and size groups.

Examples: Broken axis · Custom layouts · Marginal histograms · +18

g.geom_jitter( Display data as randomly jittered points

'width'0.2Horizontal extent of the jitter, relative to the space available for each x value
'height'0Vertical extent of the jitter, in y units
'dodge'0Spacing between points of different colors within an unique x value
'alpha'1Transparency of points, from 0 (transparent) to 1 (opaque)
'raw_width'falseSet to true to give 'width' in x units
More

Example syntax (default arguments): gramm_object.geom_jitter('width',0.2,'height',0) Useful when points overlap a lot, e.g. with discrete x or y values. Supports color, lightness, marker and size groups.

Examples: Categorical X data · Violin plots

g.geom_swarm( Display data as swarms of non-overlapping points

'type'How points are spread
'up'points placed from the lowest to the highest y value
'down'points placed from the highest to the lowest y value
'fan'points placed from the mean outwards
'hex'y values rounded to rows of points on a hexagonal grid
'square'y values rounded to rows of points on a square grid
'corral'What to do with points spreading beyond 'width'
'none'points are left where they are
'gutter'points are stacked at the edges of the width
'omit'points are not displayed
'wrap'points are folded back inside the width
'random'points are placed randomly inside the width
'point_size'3Radius of the points, in points. The swarm layout uses it, so set_point_options() and the size aesthetic don't change the size of swarm points
'dodge'0.7Spacing between swarms of different colors within an unique x value, see stat_summary()
'width'0.9Width available to each swarm, used by 'corral'
'alpha'1Transparency of the points, from 0 (transparent) to 1 (opaque)
More

Example syntax: gramm_object.geom_swarm('type','fan','point_size',2) Points with the same x value are spread horizontally so that they don't overlap (beeswarm plot). The layout depends on the size of the axes and is computed again when the figure is resized.

Examples: Categorical X data · Swarm plots

g.geom_line( Display data as lines

'dodge'0Spacing between lines of different colors within an unique x value
'alpha'1Transparency of lines, from 0 (transparent) to 1 (opaque)
'stacked'falseStack the lines of the different groups and shade the areas between them (only with 1D arrays for x and y)
'fill'[]If set to a y value, shade the area between the lines and this value
'fill_alpha'0.4Transparency of the shaded areas, from 0 to 1
'ordered'falseOrder the points of each line along x, so that the line doesn't go back on itself (only with 1D arrays for x and y)
More

Example syntax: gramm_object.geom_line('ordered',false,'alpha',1) Supports color, lightness, linestyle and size groups. If x and y are 1D arrays, all the points within a group are connected: if the data is not properly grouped/ordered things can look weird.

Examples: Dates and durations · Input formats · Log axes · +2

g.geom_raster( Display x data as a raster plot (e.g. spike times)

'geom'Raster elements
'line'vertical lines
'point'points
More

Example syntax: gramm_object.geom_raster('geom','line') Each element of x (usually a cell of arrays of event times) is displayed on its own row.

Examples: 1D distributions · Repeated measurements

g.geom_bar( Display data as bars

'width'0.6Width of the bars
'stacked'falseStack the bars of different colors instead of dodging them
'dodge'0Spacing between bars of different colors within an unique x value
'FaceColor''auto'Face color of the bars, or 'auto' for the gramm color
'EdgeColor''k'Edge color of the bars, or 'auto' for the gramm color
'fill'[]Fill style, replaces 'FaceColor' and 'EdgeColor' when set
'face'colored faces with black edges
'edge'colored edges, no faces
'all'colored faces, no edges
'transparent'colored edges and transparent colored faces
'fill_alpha'[]Transparency of the bar faces, from 0 (transparent) to 1 (opaque) (set by the fill style)
'LineWidth'[]Width of the bar edges (line size of the data, see set_line_options())
More

Example syntax (default arguments): gramm_object.geom_bar('width',0.6) When data in several colors has to be displayed, the bars of different colors are dodged or stacked.

Examples: Category ordering · Intervals · Labels

g.geom_interval( Display intervals given by the ymin and ymax data (error bars, areas)

'geom'How the intervals are displayed, one or a cell of several of the following
'area'y connected by a line, interval as a shaded transparent area
'lines'y connected by a line, interval as thin lines
'line'y connected by a line
'area_only'interval as a shaded transparent area, no line
'solid_area'y connected by a line, interval as a solid area
'errorbar'interval as colored error bars
'black_errorbar'interval as black error bars
'bar'y as colored bars
'edge_bar'y as colored bars with black edges
'point'y as points
'black_point'y as black points
'dodge'[]Spacing between intervals of different colors within an unique x value (0.6 for 'bar' with several colors, 0 otherwise)
'width'[]Width of the bars (0.8 times 'dodge' if dodging, 0.5 otherwise). The size of errorbar caps is set with set_line_options('cap_size',...)
'fill_alpha'0.2Transparency of the 'area' geom, from 0 (transparent) to 1 (opaque)
More

Example syntax: gramm_object.geom_interval('geom','area') The data must contain ymin and ymax values (see gramm()) defining the interval boundaries. Error bars are drawn with MATLAB's errorbar(): their handles in results are ErrorBar objects.

Examples: Intervals

g.geom_label( Display the label data as text

'dodge'Spacing between labels of different colors within an unique x value (default 0)
'Color'Color of the text, or 'auto' for the gramm color (default 'auto')
'EdgeColor'Color of the text box edge, can be 'auto' for the gramm color
'BackgroundColor'Color of the text box, can be 'auto' for the gramm color
More

Example syntax: gramm_object.geom_label('Color','auto','dodge',0.6) Displays the text given as 'label' to gramm(), at the x and y locations. Appearance of the text can be customized with any text() property given as 'name',value pair.

Examples: Labels

g.geom_count( Display data as points which size varies with the number of overlapping points

'scale'20Scaling factor between count and point area
'point_color'How the points are colored
'all'colored faces, no edges
'face'colored faces with black edges
'edge'colored edges, no faces
More

Example syntax: gramm_object.geom_count('scale',20)

Statistics stat_ method calls, any order

g.stat_summary( Display the location and variability of y for each unique value of x

'type'What is computed, or a function handle taking y values (as an n_repetitions x n_data_points matrix) and returning [y_central ; y_CI_low ; y_CI_high], see example below
'ci'mean and 95% confidence interval of the mean (assuming normal data)
'bootci'mean and bootstrapped 95% confidence interval of the mean
'sem'mean and standard error of the mean
'std'mean and standard deviation
'quartile'median and 25%/75% percentiles
'95percentile'median and 2.5%/97.5% percentiles
'fitnormalci'mean and 95% CI from a fitted normal distribution
'fitpoissonci'mean and 95% CI from a fitted Poisson distribution
'fitnegbinomialci'mean and 95% CI from a fitted negative binomial distribution
'fitbinomialci'mean and 95% CI from a fitted binomial distribution
'fitgammaci'scale and 95% CI from a fitted gamma distribution
'fitinvgaussianci'mean and 95% CI from a fitted inverse Gaussian distribution
'fit95percentile'median and 2.5%/97.5% percentiles of a fitted normal distribution
'geom'How the summaries are displayed, one or a cell of several of the following, e.g. {'bar','black_errorbar'}
'area'central values (mean or median) connected by a line, variability (CI, std...) as a shaded transparent area
'lines'central values connected by a line, variability as thin lines
'line'central values connected by a line
'area_only'variability as a shaded transparent area, no line
'solid_area'central values connected by a line, variability as a solid area
'errorbar'variability as colored error bars
'black_errorbar'variability as black error bars
'bar'central values as colored bars
'edge_bar'central values as colored bars with black edges
'point'central values as points
'black_point'central values as black points
'dodge'[]Spacing between elements of different colors within an unique x value, as a ratio of the x intervals. 0 deactivates dodging (0.6 for bars with several colors, 0 otherwise)
'width'[]Width of the bars (0.8 times 'dodge' if dodging, 0.5 otherwise). The size of error bar caps is set with set_line_options('cap_size',...)
'setylim'falseSet the y axis limits from the summaries instead of the data
'interp''none'Interpolate the output, with the interpolation methods of interp1() ('linear', 'spline'...). 'polar' (and closed polar plots) uses interpft(), which assumes a regular sampling around the circle
'interp_in'-1Number of x values over which the input is linearly interpolated. Must be used when x and y are given as cells and x values are not aligned. Ideally higher than the x resolution of the data, otherwise some data is unused (no interpolation)
'bin_in'[]Number of x bins over which the 1D input is summarized, or bin edges as an array (numeric, datetime or duration)
'bin_width'[]Bins the input like 'bin_in', with bins of a given width: numeric (in x units), a duration or calendarDuration (e.g. minutes(5) or calweeks(1)), or the name of a time unit for datetime/duration x data ('second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'...). Bins then fall on round values (calendar boundaries for dates). Takes precedence over 'bin_in'
'fill_alpha'0.2Transparency of the 'area' and 'area_only' geoms, from 0 (transparent) to 1 (opaque)
More

Example syntax (default arguments): gramm_object.stat_summary('type','ci','geom','area','setylim',false) By default, all y values with the same x value are summarized. If x and y are 1D arrays but x values are not discrete enough, the summaries can be computed over x bins with 'bin_in' or 'bin_width'. If x and y are given as matrices or cells with non-aligned x values, 'interp_in' must be used to align them by interpolation.

Custom summary function, here the trimmed mean with bootstrapped CI:

custom_statfun = @(y)([trimmean(y,2.5);bootci(500,{@(ty)trimmean(ty,2.5),y},'alpha',0.05)]);
gramm_object.stat_summary('type', custom_statfun)

Effect of 'dodge' and 'width' on bars of two colors:

'dodge',1,'width',1: fully dodged bars, not separated, occupying the
full interval between x values
* __    *
*|  |__ *
*|  |  |*
*|__|__|*
'dodge',0.8,'width',0.8: fully dodged bars, not separated
*  _    *
* | |_  *
* | | | *
* |_|_| *
'dodge',0.8,'width',0.6: spacing between the bars
*  _      *
* | |  _  *
* | | | | *
* |_| |_| *
'dodge',0.8,'width',1: dodged but overlapping bars
*  ___    *
* |  _|_  *
* | |   | *
* |_|___| *

Examples: Custom layouts · Categorical X data · Continuous X-Y data · +7

g.stat_smooth( Display a smoothed estimate of the data with 95% bootstrapped confidence interval

'lambda'[]Amount of smoothing, whose meaning depends on the method. With 'eilers', the lambda of the method (1000 if empty), or 'auto' to find the best one by cross-validation, separately for each group. With 'smoothingspline', the 'SmoothingParam' of fit() (0 to 1). With the smooth() methods, the span (number or fraction of points), or [span degree] for 'sgolay'
'geom'How the smooth is displayed, same as stat_summary()
'line' 'lines' 'area' 'area_only' 'solid_area' 'errorbar' 'black_errorbar' 'bar' 'edge_bar' 'point' 'black_point'
'fill_alpha'0.2Transparency of the 'area' and 'area_only' geoms, from 0 (transparent) to 1 (opaque)
'method'Smoothing method
'eilers'Eilers 2003 smoother (fast)
'smoothingspline'smoothing spline, uses fit() from the Curve Fitting Toolbox
'moving'moving average, uses smooth() from the Curve Fitting Toolbox, like the following methods
'lowess'local linear regression
'loess'local quadratic regression
'sgolay'Savitzky-Golay filter
'rlowess'robust 'lowess', less sensitive to outliers
'rloess'robust 'loess', less sensitive to outliers
'npoints'200Number of points over which the smooth is evaluated
'setylim'falseSet the y axis limits from the smooth instead of the data
More

Example syntax (default arguments): gramm_object.stat_smooth('method','eilers','geom','area') If used with repeated data (y given as a matrix or cell), each trajectory is smoothed and displayed individually, without confidence interval. The 'eilers' smoother is described in Eilers, P. H. C. (2003). A Perfect Smoother. Analytical Chemistry, 75(14), 3631-3636. http://doi.org/10.1021/ac034173t

Examples: Continuous X-Y data · Dates and durations · Repeated measurements · +1

g.stat_glm( Display a generalized linear model fit of the data with 95% confidence bounds

'distribution'Distribution of the data, as in fitglm(). 'normal' gives a standard linear model
'normal' 'binomial' 'poisson' 'gamma' 'inverse gaussian'
'geom'How the fit is displayed, same as stat_summary()
'line' 'lines' 'area' 'area_only' 'solid_area' 'errorbar' 'black_errorbar' 'bar' 'edge_bar' 'point' 'black_point'
'fill_alpha'0.2Transparency of the 'area' and 'area_only' geoms, from 0 (transparent) to 1 (opaque)
'fullrange'falseDisplay the fit over the whole x axis instead of the range of x values used for the fit
'disp_fit'falseDisplay the fitted parameters and p-value stars
More

Example syntax (default arguments): gramm_object.stat_glm('distribution','normal','geom','area','fullrange',false) Uses fitglm() from the Statistics Toolbox.

Examples: Custom layouts · Post-draw customization · Superimposed plots · +3

g.stat_fit( Display a fit of the data with a custom function

'fun'@(a,b,x)a*x+bAnonymous function fitted to the data, with the parameters as first arguments and x as last argument: @(param1,...,paramN,x). With 'stats', the parameters are given as a vector: @(b,x)
'StartPoint'[]Starting values of the parameters [param1_start ... paramN_start]
'fit_options'[]Fit options from fitoptions(), override 'StartPoint'. With 'stats', options from statset('fitnlm')
'intopt'Type of bounds computed by predint() (not with 'stats')
'observation'95% bounds for a new observation
'functional'95% bounds for the fitted function
'geom'How the fit is displayed, same as stat_summary()
'line' 'lines' 'area' 'area_only' 'solid_area' 'errorbar' 'black_errorbar' 'bar' 'edge_bar' 'point' 'black_point'
'fill_alpha'0.2Transparency of the 'area' and 'area_only' geoms, from 0 (transparent) to 1 (opaque)
'fullrange'falseDisplay the fit over the whole x axis instead of the range of x values used for the fit
'disp_fit'falseDisplay the fitted parameters
'stats'falseUse fitnlm() from the Statistics Toolbox instead of fit()
More

Example syntax: gramm_object.stat_fit('fun',@(alpha,beta,x)alpha*cos(x-beta),'disp_fit',true) Uses fit() from the Curve Fitting Toolbox, or fitnlm() from the Statistics Toolbox when 'stats' is true. With 'stats', additional 'name',value pairs for fitnlm() can be given.

Examples: Continuous X-Y data

g.stat_bin( Displays an histogram of the data in x

'nbins'30Number of bins of equal width spanning the x data
'edges'[]Bin edges, as numeric, datetime or duration values
'bin_width'[]Bin width, numeric (in x units), a duration or calendarDuration (e.g. hours(2) or calmonths(1)), or the name of a time unit for datetime/duration x data ('second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'...), in which case the bins follow calendar boundaries
'geom'How the bin counts are displayed
'bar'dodged bars
'overlaid_bar'overlaid bars (use transparency)
'stacked_bar'stacked bars
'line'counts connected by a line
'stairs'stair line
'point'counts as points
'normalization'Normalization of the bin counts, same as the 'Normalization' argument of histcounts()
'count'number of points in each bin
'probability'counts divided by the number of points (sum to 1)
'countdensity'counts divided by the bin widths
'pdf'probability density estimate (integrates to 1)
'cumcount'cumulative counts
'cdf'cumulative distribution (ends at 1)
'fill'[]Aspect of the geom (set by the geom: 'face' for bars, 'transparent' for 'overlaid_bar', 'edge' otherwise)
'face'colored faces with black edges
'edge'colored edges, no faces
'all'colored faces, no edges
'transparent'colored edges and transparent colored faces
'fill_alpha'[]Transparency of the faces, from 0 (transparent) to 1 (opaque) (set by 'fill')
'width'[]Width of the bars, relative to the bin width (same as 'dodge' if dodging, 1 otherwise)
'dodge'[]Spacing between bars of different colors within a bin (0.8 for 'bar' with several colors, 0 otherwise)
More

Example syntax (default arguments): gramm_object.stat_bin('nbins',30,'geom','bar') Bins are given by 'edges' if set, otherwise by 'bin_width' if set, otherwise by 'nbins'. If the bin widths are not equal (e.g. months), it's recommended to use 'countdensity' or 'pdf' for normalization.

Examples: Marginal histograms · Superimposed plots · 1D distributions · +5

g.stat_cornerhist( Display a histogram of the x-y differences in an inset axis at a corner of the plot

'nbins'30Number of bins, same as stat_bin()
'edges'[]Bin edges, same as stat_bin()
'bin_width'[]Bin width, same as stat_bin()
'geom'How the counts are displayed, same as stat_bin() except 'stacked_bar'
'bar' 'overlaid_bar' 'line' 'stairs' 'point'
'normalization'Normalization of the counts, same as stat_bin()
'count' 'probability' 'countdensity' 'pdf' 'cumcount' 'cdf'
'fill'[]Aspect of the geom, same as stat_bin()
'edge' 'face' 'all' 'transparent'
'fill_alpha'[]Transparency of the faces, same as stat_bin()
'width'[]Width of the bars, same as stat_bin()
'dodge'[]Spacing between bars of different colors, same as stat_bin()
'aspect'0.3Aspect ratio (y/x) of the inset axis
'location'[]x (and y) location of the inset axis on the unity line of the parent axis (the maximum of the x and y data)
More

Example syntax: gramm_object.stat_cornerhist('edges',-5:0.5:5,'aspect',0.3) The inset axis is placed on the unity line (y=x) of the parent axis, perpendicular to it. Useful to compare paired data, e.g. a measure before (x) and after (y) a treatment. Specifying 'edges' is recommended.

Examples: Continuous X-Y data · Corner histograms

g.stat_density( Display a smooth density estimate of the data in x

'bandwidth'-1Bandwidth of the kernel, as in ksdensity(). Values <= 0 for the automatic bandwidth
'function''pdf'Function estimated, as in ksdensity(): 'pdf', 'cdf', 'survivor'...
'kernel''normal'Kernel, as in ksdensity(): 'normal', 'box', 'triangle', 'epanechnikov'
'npoints'100Number of x values over which the density is evaluated
'extra_x'0.1Extension of the evaluation range on each side of the x data, as a ratio of the x data range
More

Example syntax (default arguments): gramm_object.stat_density('function','pdf','kernel','normal','npoints',100) Uses ksdensity() from the Statistics Toolbox.

Examples: Custom layouts · 1D distributions

g.stat_bin2d( Make 2D bins of x and y data and display the counts

'nbins'[30 30]Number of bins [n_xbins n_ybins]
'edges'{}Custom bin edges {x_edges y_edges}, override 'nbins'
'geom'How the counts are displayed
'image'heatmap
'contour'contour plot
'point'circles of varying size
More

Example syntax (default arguments): gramm_object.stat_bin2d('nbins',[30 30],'geom','image')

Examples: 2D distributions

g.stat_ellipse( Display confidence ellipses around 2D groups of points

'type'What the ellipse contains
'95percentile'95% of the points (assuming a bivariate normal distribution)
'ci'95% of the bootstrapped 2D means
'geom'How the ellipse is displayed
'area'shaded area with outline
'line'outline only
'fill_alpha'0.2Transparency of the 'area' geom, from 0 (transparent) to 1 (opaque)
'patch_opts'{}Additional patch() properties, as a cell of 'name',value pairs
More

Example syntax (default arguments): gramm_object.stat_ellipse('type','95percentile','geom','area')

Examples: 2D distributions

g.stat_qq( Make a quantile-quantile plot from the data in x

'distribution'makedist('Normal',0,1)Theoretical distribution against which x is plotted, created with makedist(), or 'y' to plot the distribution of x against the distribution of y
More

Example syntax (default arguments): gramm_object.stat_qq('distribution',makedist('Normal',0,1))

Examples: 1D distributions

g.stat_boxplot( Display box and whisker plots of y for each unique value of x

'width'0.6Width of the boxes, see stat_summary()
'dodge'0.7Spacing between boxes of different colors within an unique x value, see stat_summary()
'notch'falseDisplay notches at median +/- 1.58*IQR/sqrt(N)
'outliers'trueDisplay the outliers. If not set, outliers are hidden when geom_point() or geom_jitter() are used
More

Example syntax (default arguments): gramm_object.stat_boxplot('width',0.6,'dodge',0.7) The box is drawn between the 25 and 75 percentiles, with a line at the median. The whiskers extend to the most extreme data points within 1.5 times the interquartile range from the box (Tukey boxplot). Points outside the whiskers are plotted as outliers.

Examples: Custom layouts · Categorical X data · Dates and durations · +2

g.stat_violin( Display violin plots of y for each unique value of x

'bandwidth'-1Same as stat_density()
'kernel''normal'Same as stat_density()
'npoints'100Same as stat_density()
'extra_y'0Same as 'extra_x' in stat_density()
'normalization'How violins are scaled
'area'all violins have the same area
'count'areas proportional to the number of points
'width'all violins have the same maximum width
'fill'Aspect of the violins, same as stat_bin()
'edge' 'face' 'all' 'transparent'
'fill_alpha'[]Transparency of the faces, same as stat_bin() (set by 'fill')
'width'0.6Width of the violins, see stat_summary()
'dodge'0.7Spacing between violins of different colors, see stat_summary()
'half'falseDraw half violins, left or right depending on the color index. Useful to compare distributions between two colors
More

Example syntax (default arguments): gramm_object.stat_violin('normalization','area','fill','face')

Examples: Categorical X data · Violin plots

Reference lines and shapes geom_ method calls, any order

g.geom_abline( Display y=ax+b reference lines in each facet

'slope'1Slope of the lines, single value or 1D array
'intercept'0Intercept of the lines, single value or 1D array
'style''k--'MATLAB line specification giving the line style and color, or cell of line specifications
'extent'2Length of the lines, as a ratio of the axis range (lines cross the whole axis)
'line_width'1Width of the lines
'linewidth'[]Former name of 'line_width'
More

Example syntax: gramm_object.geom_abline('slope',1,'intercept',0,'style','k--') 'slope' and 'intercept' can be 1D arrays of the same size in order to draw multiple lines. In that case, 'style' can either be a single style (all lines have the same style), or a cell of styles, one per line.

Examples: Continuous X-Y data · Corner histograms

g.geom_vline( Display vertical reference lines in each facet

'xintercept'0x position of the lines, single value or 1D array. Can be datetime or duration values when the data is
'style''k--'Line specification or cell of line specifications, same as geom_abline()
'extent'2Length of the lines, same as geom_abline()
'line_width'1Width of the lines
'linewidth'[]Former name of 'line_width'
More

Example syntax: gramm_object.geom_vline('xintercept',1,'style','k--')

Examples: Group spacing · Smoothing

g.geom_hline( Display horizontal reference lines in each facet

'yintercept'0y position of the lines, single value or 1D array. Can be datetime or duration values when the data is
'style''k--'Line specification or cell of line specifications, same as geom_abline()
'extent'2Length of the lines, same as geom_abline()
'line_width'1Width of the lines
'linewidth'[]Former name of 'line_width'
More

Example syntax: gramm_object.geom_hline('yintercept',1,'style','k--')

Examples: Dates and durations · Polar plots

g.geom_funline( Display a custom curve in each facet

'fun'@(x)xAnonymous function of x, or cell of anonymous functions
'style''k--'Line specification or cell of line specifications, same as geom_abline()
'extent'2Length of the curves, same as geom_abline()
'line_width'1Width of the lines
'linewidth'[]Former name of 'line_width'
More

Example syntax: gramm_object.geom_funline('fun',@(x)3*sin(x),'style','k--')

Examples: Smoothing

g.geom_polygon( Display reference polygons in the background of each facet

'x'{}Cell of P vectors with the x coordinates of the vertices, or the [start end] of vertical bands if 'y' is not given
'y'{}Cell of P vectors with the y coordinates of the vertices, or the [start end] of horizontal bands if 'x' is not given
'alpha'0.2Former name of 'fill_alpha'
'fill_alpha'[]Fill transparency, from 0 (transparent) to 1 (opaque), single value or array of length P (uses 'alpha')
'color'[0 0 0]Fill color, RGB as a 1x3 or Px3 matrix, or indices of colors of the gramm colormap
'line_color'[0 0 0]Edge color, same format as 'color'
'line_style'{'none'}Edge style, cell of length 1 or P
'extent'2Length of the bands, as a ratio of the axis range (bands cross the whole axis)
More

Example syntax: gramm_object.geom_polygon('x',{[0 1 1]},'y',{[0 0 1]},'color',[1 0 0]) The P polygons are given in one of two ways.

With both 'x' and 'y', the i-th cell of each holds the x (or y) coordinates of the vertices of the i-th polygon, as vectors of the same length. 'x',{[0 1 1]},'y',{[0 0 1]} draws a triangle.

With only 'x' (or only 'y'), vertical (or horizontal) bands spanning the whole plot are drawn, each cell holding the [start end] of one band. 'x',{[1 2] [5 6]} draws two vertical bands.

The other options are given either once for all polygons, or once per polygon (P values, P rows or P cells).

Examples: Polygons

Options and customization Method calls, any order

g.set_names( Set names of the variables, displayed in axes labels, legends and facet titles

'x''x'Label of the x axes
'y''y'Label of the y axes
'z''z'Label of the z axes
'label''Label'Name of the label variable
'color''Color'Title of the color legend
'linestyle''Line Style'Title of the line style legend
'size''Size'Title of the size legend
'marker''Marker'Title of the marker legend
'row''Row'Title of the row facets, combined with each value
'column''Column'Title of the column facets, combined with each value
'lightness''Lightness'Title of the lightness legend
'group''Group'Name of the group variable
'fig''Figure'Title of the separate figures, combined with each value
More

Example syntax: gramm_object.set_names('x','Time (ms)','y','Hand position (mm)','color','Movement direction','row','Subject')

Examples: Custom layouts · Marginal histograms · Post-draw customization · +20

g.set_title( Add a title to the gramm plot, or to the whole figure when called on an array

titleText of the title. Can be followed by any text() property as 'name',value pairs ('FontSize', 'Color'...)
More

Example syntax: gramm_object.set_title('Title','FontSize',14) When called on a single gramm object, the title is placed above its axes. When called on an array of gramm objects, the title is placed above all of them. A figure can thus have a general title and titles for each gramm plot:

g(1,1).set_title('Subfigure 1 Title')
g(1,2).set_title('Subfigure 2 Title')
g.set_title('Global title')
g.draw()

Examples: Broken axis · Custom layouts · Post-draw customization · +23

g.set_order_options( Set the order of the categories of grouping variables

'x'Order of the x values
1ascending order (see above)
0order of first appearance in the data
-1descending order
{'S' 'M' 'L' 'XL'}the values themselves, in the desired order. Numeric, categorical, datetime or duration arrays work too ([10 34 20 5]). Values not in the data are ignored, and data whose value is missing from the list is not displayed
[3 2 1 4]the order given as indices into the values sorted in ascending order. Must contain each integer from 1 to the number of values once
'color'1Order of the color groups, same values as 'x'
'marker'1Order of the marker groups, same values as 'x'
'size'1Order of the size groups, same values as 'x'
'linestyle'1Order of the line style groups, same values as 'x'
'row'1Order of the rows of facets, same values as 'x'
'column'1Order of the columns of facets, same values as 'x'
'lightness'1Order of the lightness groups, same values as 'x'
More

Example syntax: gramm_object.set_order_options('x',0,'color',{'S' 'M' 'L' 'XL'}) The order of the categories sets their positions along categorical x axes, the order of the colors, markers... in the legends, and the order of the rows and columns of facets. Each grouping variable given to gramm() (except y) has an option with its name, set as for 'x' below.

By default, categories are sorted in ascending order: numerical for numbers, alphabetical for text, the order of the categories for categorical arrays, and chronological for datetime and duration arrays. To get the alphabetical order of a categorical array, give it to gramm as cellstr(categorical_array).

Example, with clothing sizes {'L' 'S' 'XL' 'M' 'S' ...} given as color:

'color',1                  L, M, S, XL (ascending, alphabetical)
'color',0                  L, S, XL, M (order of appearance)
'color',-1                 XL, S, M, L (descending)
'color',{'S' 'M' 'L' 'XL'} S, M, L, XL (given order)
'color',[3 2 1 4]          S, M, L, XL (indices in the ascending order)

Examples: Polar plots · Category ordering

g.set_color_options( Set the colormaps of color and lightness groups, and their legends

'map'Colormap
'lch'colormap generated in the perceptually uniform LCH color space, supports lightness. Tuned with the 'lightness_range', 'chroma_range', 'hue_range', 'lightness' and 'chroma' options
'matlab'MATLAB's own post 2014b colormap, no lightness
'brewer1'colorbrewer2.org colormap, no lightness. Also 'brewer2', 'brewer3', 'brewer_pastel' and 'brewer_dark'
'brewer_paired'colorbrewer2.org colormap, 5 colors with 2 lightness levels each
'd3_10'd3.js categorical colormap, 10 colors, no lightness
'd3_20'd3.js colormap, 10 colors with 2 lightness levels each
'd3_20b'd3.js colormap, 5 colors with 4 lightness levels each. Also 'd3_20c'
[r g b ; ...]custom colormap, one RGB row per color/lightness combination, the lightness levels of each color one after the other: color 1 lightness 1, color 1 lightness 2, ..., color 2 lightness 1... For instance [1 0 0 ; 1 0.6 0.6 ; 0 0 1 ; 0.6 0.6 1] has 2 colors (red and blue) with 2 lightness levels each. Give the numbers of colors and lightness levels with 'n_color' and 'n_lightness'
'lightness_range'[85 15]For 'lch' with lightness groups: lightness (0-100) of the first and last lightness levels (light to dark)
'chroma_range'[30 90]For 'lch' with lightness groups: chroma (0-100, the intensity of the color) of the first and last lightness levels. Light colors have a low chroma so that they stay displayable on screens (sRGB) (weak to deep colors)
'hue_range'[25 385]For 'lch': hues (0-360) of the first and last colors, the others being evenly spaced in between (red to blue)
'lightness'65For 'lch' without lightness groups: lightness (0-100) of all colors
'chroma'75For 'lch' without lightness groups: chroma (0-100) of all colors
'legend'How colors and lightness levels are shown in legends
'separate_gray'separate color and lightness legends, lightness shown in shades of gray (default for 'lch')
'separate'separate color and lightness legends, lightness shown in shades of the first color (default for other colormaps)
'expand'a single legend with all color/lightness combinations
'merge'color legend merged with the marker/line/size legends when they have the same categories
'n_color'[]Number of colors of a custom colormap
'n_lightness'[]Number of lightness levels of a custom colormap. If 'n_color' or 'n_lightness' is not given, each row of the custom colormap is a color without lightness levels
More

Example syntax (default arguments): gramm_object.set_color_options('map','lch','legend','separate_gray') Data can be grouped both by color (hue) and by lightness (light to dark shades of each color): the colormap then needs several lightness levels per color. The default 'lch' colormap is generated for the number of groups, with as many colors and lightness levels as needed. The other colormaps have a fixed number of colors and lightness levels, and give an error when there are more groups.

Examples: Marginal histograms · Superimposed plots · Polar plots · +6

g.set_continuous_color( Show numeric color values with a continuous color scale

'colormap''viridis'Name of a MATLAB colormap ('hot', 'cool'...)
'active'trueSet to false to go back to categorical colors
'LCH_colormap'[]Colormap from Lightness-Chroma-Hue values, as [L_start L_end ; C_start C_end ; H_start H_end]
'CLim'[]Color limits [color_min color_max] for all facets, automatic by default
More

Example syntax: gramm_object.set_continuous_color('colormap','viridis') By default, 'color' values are categories: one group (line, fit, violin...) per value, with a categorical palette. With set_continuous_color(), numeric color values are shown with a continuous color scale and a gradient legend instead: each point gets the color of its value, and lines are colored along their length (they are not split by color: use 'group' to separate them).

Examples: Continuous colormap · Wrap (one-to-many)

g.set_point_options( Set point size and marker options

'base_size'5Size of the points, or of the first size group
'step_size'2Size difference between successive size groups
'use_input'falseUse the numeric values of the 'size' data as point sizes, instead of size groups
'input_fun'@(v)vFunction converting the 'size' data into point sizes when 'use_input' is true, e.g. @(v)v*2
'border_width'0.5Width of the point edges
'border_color''none'Color of the point edges
'markers'{'o' 's' 'd' '^' 'v' '>' '<' 'p' 'h' '*' '+' 'x'}Markers of the marker groups, in order
More

Example syntax (default arguments): gramm_object.set_point_options('base_size',5,'step_size',2) Without a 'size' grouping variable, all points have the size 'base_size'. With one, the first size group has 'base_size' and each next group is 'step_size' larger. With 'use_input', numeric size data is used directly as point sizes instead of as groups.

Examples: Marginal histograms · Superimposed plots · 2D distributions · +4

g.set_line_options( Set line width and style options

'base_size'1.5Width of the lines, or of the first size group
'step_size'1Width difference between successive size groups
'use_input'falseUse the numeric values of the 'size' data as line widths, instead of size groups
'input_fun'@(v)vFunction converting the 'size' data into line widths when 'use_input' is true, e.g. @(v)v/2
'styles'{'-' '--' ':' '-.'}Line styles of the linestyle groups, in order
'cap_size'6Size of the error bar caps, in points
More

Example syntax (default arguments): gramm_object.set_line_options('base_size',1.5,'step_size',1) Without a 'size' grouping variable, all lines have the width 'base_size'. With one, the first size group has 'base_size' and each next group is 'step_size' wider. With 'use_input', numeric size data is used directly as line widths instead of as groups.

Examples: Point and line styles

g.set_text_options( Set text size and font options

'base_size'10Base text size, the size of axis tick labels
'label_scaling'1Size of axis labels, relative to base
'legend_scaling'1Size of legend labels, relative to base
'legend_title_scaling'1.2Size of legend titles, relative to base
'facet_scaling'1.2Size of facet titles, relative to base
'title_scaling'1.4Size of the plot title, relative to base
'big_title_scaling'1.4Size of the title of an array of gramm plots, relative to base
'font''Helvetica'Font of all text
'interpreter'Interpretation of text characters
'none' 'tex' 'latex'
'wrap'trueWrap long titles (overall, facet and row titles) on several lines to fit the available space. The title of an array of gramm plots follows the setting of its first plot
More

Example syntax (default arguments): gramm_object.set_text_options('base_size',10,'font','Helvetica')

Examples: Post-draw customization

g.set_stat_options( Set options of the statistics computed by stat_ methods

'alpha'0.05Alpha level of the confidence intervals
'nboot'200Number of bootstrap samples
More

Example syntax (default arguments): gramm_object.set_stat_options('alpha',0.05,'nboot',200)

g.set_layout_options( Change figure layout options

'legend'trueDisplay the side legend (colors, markers...). set_layout_options('legend',false) replaces no_legend()
'legend_position''auto'Separates the legend from the gramm plot and puts it at a custom [left bottom width height] position in the figure (normalized coordinates)
'redraw'trueUpdate the figure automatically on resize, see redraw(). Must be set on the first element when using an array of gramm objects
'multi_padding''compact''Padding' option of tiledlayout() between multiple gramm plots
'multi_spacing''compact''TileSpacing' option of tiledlayout() between multiple gramm plots
'padding''compact''Padding' option of tiledlayout() within a gramm plot
'spacing''compact''TileSpacing' option of tiledlayout() within a gramm plot
More

Example syntax (default arguments): gramm_object.set_layout_options('legend',true,'spacing','compact')

The position and size of gramm plots are set by tiledlayout. In order to create custom layouts (plots of different sizes, combination with regular Matlab axes), draw gramm plots in tiles of a tiledlayout using set_parent(layout,'tile',tile,'span',span).

Examples: Custom layouts · Marginal histograms · Grouping aesthetics · +1

g.set_scale( Set linear or logarithmic axes

'x'Scale of the x axis, 'linear' or 'log' (default 'linear')
'y'Scale of the y axis, 'linear' or 'log' (default 'linear')
'z'Scale of the z axis, 'linear' or 'log' (default 'linear')
More

Example syntax: gramm_object.set_scale('x','log','y','log') On log axes, the limits extend proportionally beyond the data, and exclude values at or below 0, which can't be displayed. Bars (geom_bar, stat_bin, stat_summary bars) start from the bottom of the axis. Statistics are still computed on the linear values: give logarithmically spaced bins to stat_bin() with 'edges', e.g. 'edges',logspace(0,3,20). Not supported in polar plots. axe_property('XScale','log') (and 'YScale', 'ZScale') has the same effect.

Examples: Log axes

g.set_polar( Use polar axes: x is the angle (theta) and y the radius (rho)

'unit'Unit of the x data and of the angle axis. Other angles given to gramm (bin edges, bin widths, vline intercepts) are in the same unit. Results stored in g.results are in radians
'radians' 'degrees'
'closed'falseConnect the first and last points of lines
'maxy'-1Maximum of the radius axis. Values <= 0 for the maximum of the data
More

Example syntax: gramm_object.set_polar('unit','degrees','closed',true) Categorical x values are evenly spread around the circle (radar charts). Needs MATLAB R2025a or newer. Supported: geom_point, geom_jitter, geom_line, geom_count, geom_label, geom_bar, geom_interval, geom_vline/hline/abline/funline, stat_bin, stat_density, stat_summary, stat_smooth, stat_fit, stat_glm. Other geoms and stats, z data, coord_flip(), facet_grid() 'space' and set_datetick() give an error. Angle axis orientation and range can be changed with axe_property(), e.g. 'ThetaZeroLocation','top','ThetaDir','clockwise' for compass plots.

Examples: Polar plots

g.set_datetick( Display datenum x values as dates (legacy, use datetime x data instead)

More

Example syntax: gramm_object.set_datetick('x',1,'keepticks') Only for dates given as datenum numbers. Dates given as datetime (and durations) are displayed natively by gramm and don't need set_datetick(), which is then ignored: convert datenum values with datetime(x,'ConvertFrom','datenum'). Takes the same arguments as datetick() (tick axis, date format, 'keepticks', 'keeplimits').

g.set_limit_extra( Add some breathing room around the data in the axes

x_extraExtra room on the x axis, a single ratio for both sides, or [lower upper] to set each side separately
y_extraExtra room on the y axis, same format as x_extra
z_extraOptional, extra room on the z axis, same format as x_extra
More

Example syntax: gramm_object.set_limit_extra([0.05 0.2],0.05) The extra room is a ratio of the data range: with data from 0 to 10, 0.05 extends the axis by 0.5 on each side, giving limits from -0.5 to 10.5.

Examples: Labels

g.no_legend( Remove the side legend of the plot (same as set_layout_options('legend',false))

More

Example syntax: gramm_object.no_legend() Useful when plotting multiple gramm objects with the same legend.

Examples: Superimposed plots · Grid and scale options

g.coord_flip( Exchange the x and y axes, e.g. for horizontal boxplots or violins

More

Example syntax: gramm_object.coord_flip() x data is displayed on the vertical axis and y data on the horizontal axis. Sets the axes properties 'CameraUpVector',[1 0 0], 'XDir', 'reverse' and 'YAxisLocation','left', and sets things up for correct resizing of the figure. These properties can be further modified with axe_property() to get the desired orientation and location.

Examples: Marginal histograms · Categorical X data · Grid and scale options

Drawing Last method calls

g.set_parent( Set where the gramm plot is drawn (figure, panel or tile of a tiledlayout)

parentFigure, panel or tiledlayout in which the plot is drawn
'tile'1Tile number, counted row by row, or [row column] of the tile
'span'[1 1]Number of tiles [rows columns] covered by the plot
More

Example syntax: gramm_object.set_parent(parent,'tile',1,'span',[1 1]) This allows to combine gramm plots of different sizes and regular Matlab axes in a single figure:

t=tiledlayout(2,3);
g.set_parent(t,'tile',1,'span',[2 2]);

When called on an array of gramm objects, the whole array is drawn in the given parent/tile. The parent can be in a uifigure, e.g. a panel of an App Designer app. uifigures don't redraw gramm plots when resized: call redraw() on the gramm object if needed (e.g. from a SizeChangedFcn of the app).

tiledlayout (as with nexttile()):

Examples: Custom layouts · Marginal histograms

g.draw( Draws the plot in the current figure, or in the parent given to set_parent()

More

Example syntax: gramm_object.draw() Call draw() on an array of gramm objects in order to have multiple gramm plots in a single figure, placed according to their indices in the array (g(row,column)). Call draw() again after update() to draw the new layers on the same plot. The plot is redrawn when the figure is resized, unless deactivated with set_layout_options('redraw',false).

Examples: Broken axis · Custom layouts · Marginal histograms · +28

g.redraw( Update the plot after the figure is resized (called automatically)

More

Syntax: gramm_object.redraw() Facet positions are handled by tiledlayout. redraw() wraps long titles to the available width, updates the room reserved for the legend and its vertical scale, the facet sizes when using the facet_grid() 'space' option (e.g. after changing axes limits by hand), and the elements drawn by geom_swarm() and stat_cornerhist(). It is called automatically when the figure is resized, except in uifigures (see set_parent()).

Examples: Broken axis

Superimposing layers After draw(), new layers with new data

g.update( Change the data of the next layers, with the same arguments as gramm()

More

Example syntax: gramm_object.update('color',new_color_variable) Provide only the variables to change or add: the others stay as given to gramm(). If the new x or y have a different size, all the data is replaced. Call update() after draw() (it calls draw() if needed), then add layers (geom_, stat_) and call draw() again to superimpose them. After update(), facet_grid() or facet_wrap() can only go from one facet to several (the layers drawn on the single facet are copied to the others), or from several facets to one.

Examples: Superimposed plots

Export After draw()

g.export( Export gramm plot to vector or bitmap image

'file_name''gramm_export'Name of the file, the extension is added according to 'file_type'
'export_path'''Path of the destination folder, absolute or relative (current folder)
'file_type'Format of the file
'svg'vector
'pdf'vector
'eps'vector
'png'bitmap
'jpg'bitmap
'width'Width of the exported figure in 'units'. By default (recommended), the exported figure looks the same as the on-screen plot. Setting it manually is tricky
'height'Height of the exported figure in 'units', see 'width'
'units'Units of 'width' and 'height'
'centimeters' 'inches'
'resolution'0Resolution in dpi, 0 for screen resolution
More

Example syntax: gramm_object.export('file_name','my_figure','export_path','./test/','file_type','pdf') export() must be called after draw().