File Exchange

image thumbnail

rug plots

version 1.3.0.0 (2.61 KB) by Rob Campbell
Creates a so-called "rug" plot similar to those produced by the free stats package, R.

4 Downloads

Updated 18 Jun 2010

View Version History

View License

A rug plot is a compact way of illustrating the marginal distributions of a variable along x and y. Positions of the data points along x and y are denoted by tick marks, reminiscent of the tassels on a rug.

Known Issues:
Rug marks are overlaid onto the same axis as the original data. Changing the axis dimensions after calling rug will therefore cause the tick marks to become disassociated from the axes.

I haven't tested this function extensively so let me know if you find any problems.

Cite As

Rob Campbell (2020). rug plots (https://www.mathworks.com/matlabcentral/fileexchange/27582-rug-plots), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

Alfred CHEN

Sorry to disturb you, but here is another problem: As I am using the histfit function, when I delete the y-axis Rug, the rug lines on the x-axis is actually uniformly distributed. Could you help me on this one?

Rob Campbell

That's odd. Which version of MATLAB are you using? Can you confirm that you indeed see the rug lines along the edges of the plot?

Alfred CHEN

when I implement your code:
>> R=rug;
>> delete(R.yRug)
to just show the rug figure on x-axis, MATLAB reports an error:
Unrecognized function or variable 'handles'.

Error in rug (line 127)
varargout{1}=handles;

Error in stockCharacteristicAnalysis (line 16)
R = rug;
Do you know how can I fix it? Thank you very much!

Rob Campbell

Captain, what you want to do is make your plot then do:
>> R=rug;
>> delete(R.yRug)

See the function help. Your usage "rug(x)" is not a valid way of calling the function.

Captain

a=rand(100,1);
plot(a)
rug(x)
% I want to show "rug" on X-axis only, how? it seems wrong, thanks for reply.

Carl Witthoft

Nice -- did what I expected for a few quick tests.
Feature request: allow addition of 'jitter' to data so that repeated values are drawn with slight offsets so as to provide better qualitative view of the density. (I believe the R function has this option).

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: marginalscatter

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!