# gramm
Gramm is a powerful plotting toolbox which allows to quickly create complex, publication-quality figures in Matlab, and is inspired by R's [ggplot2](http://ggplot2.org) library by [Hadley Wickham](http://had.co.nz). As a reference to this inspiration, gramm stands for **GRAM**mar of graphics for **M**atlab.
## Table of contents ##
- [Why gramm?](#why-gramm)
- [Citing gramm](#citing-gramm)
- [About gramm](#about-gramm)
- [Using gramm](#using-gramm)
- [Features](#features)
- [Use cases and examples (screenshots)](#use-cases-and-examples)
## Why gramm ##
Gramm is a data visualization toolbox for Matlab that allows to produce publication-quality plots from grouped data easily and flexibly. Matlab can be used for complex data analysis using a high-level interface: it supports mixed-type tabular data via tables, provides statistical functions that accept these tables as arguments, and allows users to adopt a split-apply-combine approach ([Wickham 2011](https://www.jstatsoft.org/article/view/v040i01)) with ```rowfun()```. However, the standard plotting functionality in Matlab is mostly low-level, allowing to create axes in figure windows and draw geometric primitives (lines, points, patches) or simple statistical visualizations (histograms, boxplots) from numerical array data. Producing complex plots from grouped data thus requires iterating over the various groups in order to make successive statistical computations and low-level draw calls, all the while handling axis and color generation in order to visually separate data by groups. The corresponding code is often long, not easily reusable, and makes exploring alternative plot designs tedious.
Inspired by ggplot2 ([Wickham 2009](http://ggplot2.org)), the R implementation of "grammar of graphics" principles ([Wilkinson 1999](http://www.springer.com/de/book/9781475731002)), gramm improves Matlab's plotting functionality, allowing to generate complex figures using high-level object-oriented code.
Gramm has been used in several publications in the field of neuroscience, from human psychophysics ([Morel et al. 2017](https://doi.org/10.1371/journal.pbio.2001323)), to electrophysiology ([Morel et al. 2016](https://doi.org/10.1088/1741-2560/13/1/016002); [Ferrea et al. 2017](https://doi.org/10.1152/jn.00504.2017)), human functional imaging ([Wan et al. 2017](https://doi.org/10.1002/hbm.23932)) and animal training ([Berger et al. 2017](https://doi.org/10.1152/jn.00614.2017)).
## Citing gramm ##
Gramm has been published in the Journal of Open Source Software. If you use gramm plots in a publication you can thus cite it using the following:
[![DOI](http://joss.theoj.org/papers/10.21105/joss.00568/status.svg)](https://doi.org/10.21105/joss.00568)
Morel, (2018). Gramm: grammar of graphics plotting in Matlab. Journal of Open Source Software, 3(23), 568, https://doi.org/10.21105/joss.00568
## About gramm ##
### Compatibility ###
Tested under Matlab 2014b+ versions. With pre-2014b versions, gramm forces <code>'painters'</code>, renderer to avoid some graphic bugs, which deactivates transparencies (use non-transparent geoms, for example <code>stat_summary('geom','lines')</code>). The statistics toolbox is required for some methods: <code>stat_glm()</code>, some <code>stat_summary()</code> methods, <code>stat_density()</code>. The curve fitting toolbox is required for <code>stat_fit()</code>.
### Installation ###
Download the gramm toolbox from GitHub ("Clone or download" button>download ZIP) or [clone it](https://help.github.com/articles/cloning-a-repository/), and add the folder containing the @gramm class folder to your Matlab path (using the [GUI](https://mathworks.com/help/matlab/matlab_env/add-remove-or-reorder-folders-on-the-search-path.html) or [```addpath()```](https://mathworks.com/help/matlab/ref/addpath.html))
### Documentation ###
- [gramm cheat sheet](https://github.com/piermorel/gramm/blob/master/gramm%20cheat%20sheet.pdf)
- Numerous coding examples and test cases in ```examples.m```, exported for preview in [html/examples.html](http://htmlpreview.github.io/?https://github.com/piermorel/gramm/blob/master/html/examples.html)
- From MATLAB: <code>doc gramm</code> to find links to the documentation of each method.
## Using gramm ##
### Workflow ###
The typical workflow to generate a figure with gramm is the following:
- In a first step, provide gramm with the relevant data for the figure: X and Y variables, but also grouping variables that will determine color, subplot rows/columns, etc.
- In the next steps, add graphical layers to your figure: raw data layers (directly plot data as points, lines...) or statistical layers (plot fits, histograms, densities, summaries with confidence intervals...). One instruction is enough to add each layer, and all layers offer many customization options.
- In the last step, gramm draws the figure, and takes care of all the annoying parts: no need to loop over colors or subplots, colors and legends are generated automatically, axes limits are taken care of, etc.
For example, with gramm, 7 lines of code are enough to create the figure below from the <code>carbig</code> dataset. Here the figure represents the evolution of fuel economy of new cars in time, with number of cylinders indicated by color, and regions of origin separated across subplot columns:
<img src="/html/examples_01.png" alt="gramm example" width="800">
```matlab
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 of production) and y (fuel economy) data,
% color grouping data (number of cylinders) and select a subset of the data
g=gramm('x',Model_Year,'y',MPG,'color',Cylinders,'subset',Cylinders~=3 & Cylinders~=5)
% Subdivide the data in subplots horizontally by region of origin
g.facet_grid([],origin_region)
% Plot raw data as points
g.geom_point()
% Plot linear fits of the data with associated confidence intervals
g.stat_glm()
% Set appropriate names for legends
g.set_names('column','Origin','x','Year of production','y','Fuel economy (MPG)','color','# Cylinders')
%Set figure title
g.set_title('Fuel economy of new cars between 1970 and 1982')
% Do the actual drawing
g.draw()
```
### Figure export
To export figures in a vector-based format, use the SVG or PDF option rather than EPS. SVG can be read by all vector editing softwares and causes less problems than EPS both for export and import (transparency support, text without cuts, etc.). gramm has a convenient <code>export()</code> method that can be called after <code>draw()</code> and maintains correct dimensions/aspect ratio. The <code>'alpha'</code> option for <code>geom_line()</code> and <code>geom_point()</code> is not supported by Matlab for exports.
## Features
- Accepts X Y and Z data as arrays, matrices or cells of arrays
- Accepts grouping data as arrays or cellstr.
- Multiple ways of separating groups of data:
- Colors, lightness, point markers, line styles, and point/line size (<code>'color'</code>, <code>'lightness'</code>, <code>'marker'</code>, <code>'linestyle'</code>, <code>'size'</code>)
- Subplots by row and/or columns, or wrapping columns (<code>facet_grid()</code> and <code>facet_wrap()</code>). Multiple options for consistent axis limits across facets, rows, columns, etc. (using <code>'scale'</code> and <code>'space'</code>)
- Separate figures (<code>fig()</code>)
- Multiple ways of directly plotting the data:
- scatter plots (<code>geom_point()</code>) and jittered scatter plot (<code>geom_jitter()</code>)
- lines (<code>geom_line()</code>)
- confidence intervals (<code>geom_interval()</code>)
- bars plots (<code>geom_bar()</code>)
- raster plots (<code>geom_raster()</code>)
- labels (<code>geom_label()</code>)
- point counts (<code>point_count()</code>)
- Multiple ways of plotting statistics on the data:
- y data summarized by x values (uniques or binned) with confide
没有合适的资源?快使用搜索试试~ 我知道了~
gramm数据可视化工具箱附matlab代码.zip
共134个文件
m:78个
png:44个
md:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 73 浏览量
2024-01-26
21:22:39
上传
评论
收藏 2.36MB ZIP 举报
温馨提示
1.程序语言为matlab,程序可出预测效果图,迭代优化图,相关分析图,运行环境matlab2020b及以上。 2.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 3.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 4.作者介绍:某大厂资深算法工程师,从事Matlab算法仿真工作10年;擅长智能优化算法、神经网络预测、信号处理、元胞自动机等多种领域的算法仿真实验,更多仿真源码、数据集定制私信+。
资源推荐
资源详情
资源评论
收起资源包目录
gramm数据可视化工具箱附matlab代码.zip (134个子文件)
paper.bib 12KB
examples.html 148KB
functionSignatures.json 21KB
codemeta.json 984B
LICENSE 1KB
draw.m 56KB
examples.m 50KB
redraw.m 20KB
stat_summary.m 16KB
set_continuous_color.m 14KB
stat_smooth.m 13KB
get_colormap.m 10KB
gramm.m 10KB
stat_cornerhist.m 9KB
plotci.m 8KB
my_histplot.m 7KB
stat_violin.m 6KB
stat_ellipse.m 5KB
geom_line.m 5KB
stat_boxplot.m 5KB
geom_polygon.m 4KB
draw_polar_axes.m 4KB
stat_bin2d.m 4KB
geom_bar.m 4KB
export.m 4KB
set_color_options.m 3KB
geom_point.m 3KB
stat_glm.m 3KB
stat_fit.m 3KB
validate_aes.m 3KB
pa_LCH2RGB.m 3KB
facet_grid.m 3KB
set_layout_options.m 3KB
stat_density.m 3KB
dodge_comp.m 3KB
fill_legend.m 3KB
geom_label.m 2KB
stat_qq.m 2KB
geom_raster.m 2KB
fill_gradient_legend.m 2KB
my_tightplot.m 2KB
draw_polygons.m 2KB
geom_jitter.m 2KB
unique_and_sort.m 2KB
update.m 2KB
facet_wrap.m 2KB
set_order_options.m 2KB
stat_bin.m 1KB
set_text_options.m 1KB
geom_count.m 1KB
geom_interval.m 1KB
set_point_options.m 1KB
parse_aes.m 1KB
set_line_options.m 1019B
set_names.m 1012B
set_title.m 1001B
to_polar.m 883B
coord_flip.m 876B
set_limit_extra.m 862B
padded_cell2mat.m 861B
geom_abline.m 831B
combnan.m 743B
fill_abline.m 741B
point_patch.m 670B
set_polar.m 632B
my_histcounts.m 619B
axe_property.m 611B
geom_funline.m 583B
geom_hline.m 564B
geom_vline.m 559B
unique_no_nan.m 546B
dodger.m 546B
my_errorbar.m 517B
parse_fill.m 508B
set_datetick.m 502B
fig.m 423B
comb.m 331B
my_addParameter.m 287B
set_stat_options.m 277B
select_aes.m 271B
multi_sel.m 191B
no_legend.m 182B
pval_to_star.m 125B
example_data.mat 12KB
README.md 14KB
paper.md 8KB
CONTRIBUTING.md 2KB
paper.pdf 358KB
gramm cheat sheet.pdf 131KB
figure.png 299KB
examples_08.png 87KB
examples_09.png 80KB
examples_11.png 70KB
examples_12.png 68KB
examples_02.png 66KB
examples_06.png 64KB
examples_33.png 62KB
examples_18.png 58KB
1.png 56KB
examples_29.png 54KB
共 134 条
- 1
- 2
资源评论
matlab科研助手
- 粉丝: 1w+
- 资源: 1994
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功