Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lines joining when grouping varible has large number of categories #101

Open
JKHopf opened this issue Jun 11, 2020 · 1 comment
Open

Lines joining when grouping varible has large number of categories #101

JKHopf opened this issue Jun 11, 2020 · 1 comment

Comments

@JKHopf
Copy link

JKHopf commented Jun 11, 2020

Hi Pier,

Thank you for a wonderful toolbox!

I seem to have found a minor bug when using geom_line with a grouping variable for colour that has >15 categories - the lines all join up to become one continuous line:

% grouping variable for colour
col = 1:16;

% create 2D arrays
x = repmat(1:10,16,1);
y = [];
for i = 1:length(col)
    y(i,:) = col(i)*(x(1,:).^2) + col(i)*100;
end

% create 1D column arrays
x2 = reshape(x',[],1);
y2 = reshape(y',[],1);
col2 = reshape(repmat(col,10,1),[],1);

% draw glitchy figure
g1 = gramm('x', x2, 'y', y2, 'color', col2);
g1.geom_line();
figure()
g1.draw();

image

The bug goes away when the number of categories is <16. With this number of categories it also plots the colors as discrete in the legend, while they are continous in all other cases. The latter is not an issue in my specific example/application, but I'm not sure how it handles when the categories are not numeric and >16.

g4 = gramm('x', x2, 'y', y2, 'color', col2, 'subset', col2<16);
g4.geom_line();
figure()
g4.draw();

image

I can work around the problem using 'group':

g3 = gramm('x', x2, 'y', y2, 'color', col2, 'group', col2);
g3.geom_line();
figure()
g3.draw();

Or by having the input data as 2D arrays rather than column vectors:

g2 = gramm('x', x, 'y', y, 'color', col);
g2.geom_line();
figure()
g2.draw();

The last two both produce the same image:
image

However, it seems like a bit of a strange cutoff value? Has this been done for a particular reason or is it a genuine bug?

Cheers

@piermorel
Copy link
Owner

Hi,

Yes I did chose 15 as a cutoff value for switching between color as categories and colors as continuous values, the thinking being that it's around that number of groups that the colors become indissociable anyway. I do agree it's a bit arbitrary. An other way to solve the issue and keep more than 15 categories (apart from what you found), is to provide a categorical variable or a cell of strings to specify the color (i.e. something non numeric), it should work correctly.

I do agree that even all that said, your first figure is quite unexpected, I'll try to look if it's an easy fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants