Skip to content
/ gramm Public
forked from piermorel/gramm

Gramm is a powerful visualization toolbox which allows to quickly create complex, publication-quality figures in Matlab, and is inspired by R's ggplot2 library. As a reference to this inspiration, gramm stands for GRAMmar of graphics for Matlab.

License

Notifications You must be signed in to change notification settings

niuwk/gramm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gramm

Introduction

Gramm allows to easily plot grouped data in Matlab, and is inspired by R's ggplot2 library by Hadley Wickham

With gramm, 6 lines of code are enough to create such a figure: gramm example

load carbig.mat %Load example dataset about cars
origin_region=num2cell(org,2); %Convert origin data to a cellstr
%Create a gramm object, provide x (year) and y (mpg) data
%color data (region of origin) and select a subset of the data
g=gramm('x',Model_Year,'y',MPG,'color',origin_region,'subset',Cylinders~=3 & Cylinders~=5,'size',5)
%Set appropriate names for legends
g.set_names('color','Origin','x','Year of production','y','MPG','column','# Cylinders')
%Subdivide the data in subplots horizontally by number of cylinders
g.facet_grid([],Cylinders)
%Plot raw data points
g.geom_point()
%Plot summarized data: 5 bins over x are created and for each
%bin the mean and confidence interval is displayed as a shaded area
g.stat_summary('geom','area','type','bootci','bin_in',5)
g.draw() %Draw method

Features

  • Accepts x and y data as arrays, matrices or cells of arrays
  • Accepts grouping data as arrays or cellstr
  • Multiple ways of separating data by groups:
    • Color, point size and line type
    • Subplots by row and/or columns, or wrapping columns (facet_grid() and facet_wrap())
  • Multiple ways of directly plotting the data:
    • scatter plots (geom_point()) and jittered scatter plot (geom_jitter())
    • lines (geom_line())
    • bars plots (geom_bar())
    • raster plots (geom_raster())
  • Multiple ways of plotting transformed data:
    • y data summarized by unique x values with confidence intervals (stat_summary())
    • spline-smoothed y data with optional confidence interval (stat_smooth())
    • histograms and density plots of x values (stat_bin() and stat_density())
    • 2D binning (stat_bin2d())
    • GLM fits (stat_glm(), requires statistics toolbox)
  • Subplots are created without too much empty space in between (and resize properly !)
  • Polar plots (set_polar())
  • Confidence intervals as shaded areas, error bars or thin lines
  • Multiple gramm plots can be combined in the same figure by creatin a matrix of gramm objects and calling the draw() method on the whole matrix.
  • Matlabs axes properties are acessible through the method axe_property()
  • Custom legend labels with set_names()

Examples

Multiple gramm objects in a single figure

Also shows histograms, categorical x values Multiple gramm

Fits (carbig data)

Multiple gramm

Continuous colors

Multiple gramm

Acknowledgements

gramm was inspired and/or used code from:

About

Gramm is a powerful visualization toolbox which allows to quickly create complex, publication-quality figures in Matlab, and is inspired by R's ggplot2 library. As a reference to this inspiration, gramm stands for GRAMmar of graphics for Matlab.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • MATLAB 69.5%
  • HTML 30.4%
  • M 0.1%