Proportional Venn Diagrams

Draws a venn diagram for two or three sets with proportional areas.
7.8K Downloads
Updated 28 Oct 2004

No License

%
% function error = vennX( data, resolution )
%
% vennX - draws an area proportional venn diagram
%
% Draws a venn diagram (either two or three set) using
% circles, where the area of each region is proportional
% to the input values.
%
% INPUT:
% data - a vector of counts for each set partition
%
% For a two circle diagram:
% data is a three element vector of:
% |A|
% |A and B|
% |B|
%
% For a three circle diagram:
% data is a seven element vector of:
% |A|
% |A and B|
% |B|
% |B and C|
% |C|
% |C and A|
% |A and B and C|
%
% resolution - A measure of accuracy on the image,
% typical values are within 1/100 to 1/1000 of
% the maximum partition count. Note that smaller
% resolutions take longer compute time.
%
% OUTPUT:
% error - the difference in area of each partition
% between the actual area and the input vector
%
% EXAMPLES:
%
% vennX( [ 106 26 257 ], .05 )
%
% vennX( [ 75 143 210 ], .1 )
%
% vennX( [ 16 3 10 6 19 8 3 ], .05 )
%
%
% COMMENTS:
%
% The implementation is trivial, for the two circle case, two circles
% are drawn to scale and moved closer and closer together until the
% overlap is 'near' to the desired intersection. For the three
% circle case, it is repeated three times, once for each pair of
% circles. Hence the two circle case is almost exact, whereas the
% three circle case has much more error since the area |A and B and C|
% is derived. This means that large variations from random, especially
% close to zero, will have larger errors, for example
%
% vennX( [ 20 10 20 10 20 10 0], .1 )
%
% as opposed to
%
% vennX( [ 20 10 20 10 20 10 10], .1 )
%
% ENHANCEMENTS
%
% The implementation could be sped up tremendously using a MRA
% (multi-resolutional analysis) type algorithm. e.g. start with a
% resolution of .5 and find the distance between the circles, then use
% that as a seed for a resolution of .1, then .05, .01, etc.
%
% The error vector could be used as a measure to 'perturb' the position
% of the third circle as to minimize the error. This could be done
% with a simple gradient descent method. This would help the
% exceptions described above where the distribution deviates from
% random.
%
% When small mishapen areas are drawn, the text does not match up, e.g.
% vennX( [ 15 143 210 ], .1 )
%
%
% Original implementation and method by Jeremy Heil, for the Order of
% the Red Monkey, and the Tengu
%
% Oct. 2004
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Cite As

Jeremy Heil (2024). Proportional Venn Diagrams (https://www.mathworks.com/matlabcentral/fileexchange/6116-proportional-venn-diagrams), MATLAB Central File Exchange. Retrieved .

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

Inspired: venn

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0