Plotting group variable excluding some categories based on condition












1















I want to plot an histogram of a group variable. For this I can use categorical.



I am using an example, using summary(Group), to explain:



variable.group={'one','three','four','one','three','four','two','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four'}
Group=categorical(variable.group)
summary(Group)
figure,histogram(Group),title('Summary Group')


enter image description here



I could also use tabulate(Group) to give this result:



Group_tabulated =
4×3 cell array
'four' [10] [33.3333]
'one' [ 9] [ 30]
'three' [10] [33.3333]
'two' [ 1] [ 3.3333]


Now, as we see in above plot, there is a group with very little occurrence; I want to exclude that category to focus on the 3 most important ones.



Now using condition on tabulate, I have managed to nearly done it. But I have an issue since the category I want to exclude is still showing... just at 0 now.



Group_tabulated = tabulate(Group)
idx_largest=cell2mat(Group_tabulated(:,2))>3
Group_to_display=Group_tabulated(idx_largest,1)
Learn1_1n_largest=Group(ismember(Group,Group_tabulated(idx_largest,1)))
summary(Learn1_1n_largest)
figure,histogram(Learn1_1n_largest),title('Summary Group largest only')


enter image description here



2 questions:




  1. Can we make the solution with tabulate work, so it exclude that category data from Learn1_1n_largest?

  2. Can I use a different method just using some conditions on either categorical or on histogram for this?


Thanks in advance!










share|improve this question

























  • Can you add a Minimal, Complete, and Verifiable example

    – Ander Biguri
    Nov 23 '18 at 11:43











  • @AnderBiguri: I have added an example. hope that makes it easier to understand :-)

    – Nico
    Nov 23 '18 at 13:41











  • There is something I don't understand, it is why the category 'two' is showing if it is not within the new categorical variable Learn1_1n_largest

    – Nico
    Nov 23 '18 at 13:47
















1















I want to plot an histogram of a group variable. For this I can use categorical.



I am using an example, using summary(Group), to explain:



variable.group={'one','three','four','one','three','four','two','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four'}
Group=categorical(variable.group)
summary(Group)
figure,histogram(Group),title('Summary Group')


enter image description here



I could also use tabulate(Group) to give this result:



Group_tabulated =
4×3 cell array
'four' [10] [33.3333]
'one' [ 9] [ 30]
'three' [10] [33.3333]
'two' [ 1] [ 3.3333]


Now, as we see in above plot, there is a group with very little occurrence; I want to exclude that category to focus on the 3 most important ones.



Now using condition on tabulate, I have managed to nearly done it. But I have an issue since the category I want to exclude is still showing... just at 0 now.



Group_tabulated = tabulate(Group)
idx_largest=cell2mat(Group_tabulated(:,2))>3
Group_to_display=Group_tabulated(idx_largest,1)
Learn1_1n_largest=Group(ismember(Group,Group_tabulated(idx_largest,1)))
summary(Learn1_1n_largest)
figure,histogram(Learn1_1n_largest),title('Summary Group largest only')


enter image description here



2 questions:




  1. Can we make the solution with tabulate work, so it exclude that category data from Learn1_1n_largest?

  2. Can I use a different method just using some conditions on either categorical or on histogram for this?


Thanks in advance!










share|improve this question

























  • Can you add a Minimal, Complete, and Verifiable example

    – Ander Biguri
    Nov 23 '18 at 11:43











  • @AnderBiguri: I have added an example. hope that makes it easier to understand :-)

    – Nico
    Nov 23 '18 at 13:41











  • There is something I don't understand, it is why the category 'two' is showing if it is not within the new categorical variable Learn1_1n_largest

    – Nico
    Nov 23 '18 at 13:47














1












1








1








I want to plot an histogram of a group variable. For this I can use categorical.



I am using an example, using summary(Group), to explain:



variable.group={'one','three','four','one','three','four','two','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four'}
Group=categorical(variable.group)
summary(Group)
figure,histogram(Group),title('Summary Group')


enter image description here



I could also use tabulate(Group) to give this result:



Group_tabulated =
4×3 cell array
'four' [10] [33.3333]
'one' [ 9] [ 30]
'three' [10] [33.3333]
'two' [ 1] [ 3.3333]


Now, as we see in above plot, there is a group with very little occurrence; I want to exclude that category to focus on the 3 most important ones.



Now using condition on tabulate, I have managed to nearly done it. But I have an issue since the category I want to exclude is still showing... just at 0 now.



Group_tabulated = tabulate(Group)
idx_largest=cell2mat(Group_tabulated(:,2))>3
Group_to_display=Group_tabulated(idx_largest,1)
Learn1_1n_largest=Group(ismember(Group,Group_tabulated(idx_largest,1)))
summary(Learn1_1n_largest)
figure,histogram(Learn1_1n_largest),title('Summary Group largest only')


enter image description here



2 questions:




  1. Can we make the solution with tabulate work, so it exclude that category data from Learn1_1n_largest?

  2. Can I use a different method just using some conditions on either categorical or on histogram for this?


Thanks in advance!










share|improve this question
















I want to plot an histogram of a group variable. For this I can use categorical.



I am using an example, using summary(Group), to explain:



variable.group={'one','three','four','one','three','four','two','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four','one','three','four'}
Group=categorical(variable.group)
summary(Group)
figure,histogram(Group),title('Summary Group')


enter image description here



I could also use tabulate(Group) to give this result:



Group_tabulated =
4×3 cell array
'four' [10] [33.3333]
'one' [ 9] [ 30]
'three' [10] [33.3333]
'two' [ 1] [ 3.3333]


Now, as we see in above plot, there is a group with very little occurrence; I want to exclude that category to focus on the 3 most important ones.



Now using condition on tabulate, I have managed to nearly done it. But I have an issue since the category I want to exclude is still showing... just at 0 now.



Group_tabulated = tabulate(Group)
idx_largest=cell2mat(Group_tabulated(:,2))>3
Group_to_display=Group_tabulated(idx_largest,1)
Learn1_1n_largest=Group(ismember(Group,Group_tabulated(idx_largest,1)))
summary(Learn1_1n_largest)
figure,histogram(Learn1_1n_largest),title('Summary Group largest only')


enter image description here



2 questions:




  1. Can we make the solution with tabulate work, so it exclude that category data from Learn1_1n_largest?

  2. Can I use a different method just using some conditions on either categorical or on histogram for this?


Thanks in advance!







matlab histogram categorical-data






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 13:41







Nico

















asked Nov 23 '18 at 9:20









NicoNico

488




488













  • Can you add a Minimal, Complete, and Verifiable example

    – Ander Biguri
    Nov 23 '18 at 11:43











  • @AnderBiguri: I have added an example. hope that makes it easier to understand :-)

    – Nico
    Nov 23 '18 at 13:41











  • There is something I don't understand, it is why the category 'two' is showing if it is not within the new categorical variable Learn1_1n_largest

    – Nico
    Nov 23 '18 at 13:47



















  • Can you add a Minimal, Complete, and Verifiable example

    – Ander Biguri
    Nov 23 '18 at 11:43











  • @AnderBiguri: I have added an example. hope that makes it easier to understand :-)

    – Nico
    Nov 23 '18 at 13:41











  • There is something I don't understand, it is why the category 'two' is showing if it is not within the new categorical variable Learn1_1n_largest

    – Nico
    Nov 23 '18 at 13:47

















Can you add a Minimal, Complete, and Verifiable example

– Ander Biguri
Nov 23 '18 at 11:43





Can you add a Minimal, Complete, and Verifiable example

– Ander Biguri
Nov 23 '18 at 11:43













@AnderBiguri: I have added an example. hope that makes it easier to understand :-)

– Nico
Nov 23 '18 at 13:41





@AnderBiguri: I have added an example. hope that makes it easier to understand :-)

– Nico
Nov 23 '18 at 13:41













There is something I don't understand, it is why the category 'two' is showing if it is not within the new categorical variable Learn1_1n_largest

– Nico
Nov 23 '18 at 13:47





There is something I don't understand, it is why the category 'two' is showing if it is not within the new categorical variable Learn1_1n_largest

– Nico
Nov 23 '18 at 13:47












1 Answer
1






active

oldest

votes


















0














I have found the solution to my first question. It is possible to use removecats in order to remove all unused categories. It is simple by just not specifying anything else that the categorical as such Learn1_1n_largest=removecats(Learn1_1n_largest). The full solution to my first question is:



variable.group={'one','three','four','one','three','four','two','three','four','one','three','four','one','three','four','one','three','four', ...
'one','three','four','one','three','four','one','three','four','one','three','four'}
Group=categorical(variable.group)
summary(Group)
figure,histogram(Group),title('Summary Group')
Group_tabulated = tabulate(Group)
idx_largest=cell2mat(Group_tabulated(:,2))>3
Group_to_display=Group_tabulated(idx_largest,1)
Learn1_1n_largest=Group(ismember(Group,Group_tabulated(idx_largest,1)))
figure,histogram(Learn1_1n_largest),title('Summary Group largest only')
Learn1_1n_largest=removecats(Learn1_1n_largest)
figure,histogram(Learn1_1n_largest),title('Summary Group largest only')


I would be glad if anyone has the solution of my second question, as I hope that there would be a simpler solution without having to use both categorical & tabulate.



Thanks!






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443745%2fplotting-group-variable-excluding-some-categories-based-on-condition%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I have found the solution to my first question. It is possible to use removecats in order to remove all unused categories. It is simple by just not specifying anything else that the categorical as such Learn1_1n_largest=removecats(Learn1_1n_largest). The full solution to my first question is:



    variable.group={'one','three','four','one','three','four','two','three','four','one','three','four','one','three','four','one','three','four', ...
    'one','three','four','one','three','four','one','three','four','one','three','four'}
    Group=categorical(variable.group)
    summary(Group)
    figure,histogram(Group),title('Summary Group')
    Group_tabulated = tabulate(Group)
    idx_largest=cell2mat(Group_tabulated(:,2))>3
    Group_to_display=Group_tabulated(idx_largest,1)
    Learn1_1n_largest=Group(ismember(Group,Group_tabulated(idx_largest,1)))
    figure,histogram(Learn1_1n_largest),title('Summary Group largest only')
    Learn1_1n_largest=removecats(Learn1_1n_largest)
    figure,histogram(Learn1_1n_largest),title('Summary Group largest only')


    I would be glad if anyone has the solution of my second question, as I hope that there would be a simpler solution without having to use both categorical & tabulate.



    Thanks!






    share|improve this answer




























      0














      I have found the solution to my first question. It is possible to use removecats in order to remove all unused categories. It is simple by just not specifying anything else that the categorical as such Learn1_1n_largest=removecats(Learn1_1n_largest). The full solution to my first question is:



      variable.group={'one','three','four','one','three','four','two','three','four','one','three','four','one','three','four','one','three','four', ...
      'one','three','four','one','three','four','one','three','four','one','three','four'}
      Group=categorical(variable.group)
      summary(Group)
      figure,histogram(Group),title('Summary Group')
      Group_tabulated = tabulate(Group)
      idx_largest=cell2mat(Group_tabulated(:,2))>3
      Group_to_display=Group_tabulated(idx_largest,1)
      Learn1_1n_largest=Group(ismember(Group,Group_tabulated(idx_largest,1)))
      figure,histogram(Learn1_1n_largest),title('Summary Group largest only')
      Learn1_1n_largest=removecats(Learn1_1n_largest)
      figure,histogram(Learn1_1n_largest),title('Summary Group largest only')


      I would be glad if anyone has the solution of my second question, as I hope that there would be a simpler solution without having to use both categorical & tabulate.



      Thanks!






      share|improve this answer


























        0












        0








        0







        I have found the solution to my first question. It is possible to use removecats in order to remove all unused categories. It is simple by just not specifying anything else that the categorical as such Learn1_1n_largest=removecats(Learn1_1n_largest). The full solution to my first question is:



        variable.group={'one','three','four','one','three','four','two','three','four','one','three','four','one','three','four','one','three','four', ...
        'one','three','four','one','three','four','one','three','four','one','three','four'}
        Group=categorical(variable.group)
        summary(Group)
        figure,histogram(Group),title('Summary Group')
        Group_tabulated = tabulate(Group)
        idx_largest=cell2mat(Group_tabulated(:,2))>3
        Group_to_display=Group_tabulated(idx_largest,1)
        Learn1_1n_largest=Group(ismember(Group,Group_tabulated(idx_largest,1)))
        figure,histogram(Learn1_1n_largest),title('Summary Group largest only')
        Learn1_1n_largest=removecats(Learn1_1n_largest)
        figure,histogram(Learn1_1n_largest),title('Summary Group largest only')


        I would be glad if anyone has the solution of my second question, as I hope that there would be a simpler solution without having to use both categorical & tabulate.



        Thanks!






        share|improve this answer













        I have found the solution to my first question. It is possible to use removecats in order to remove all unused categories. It is simple by just not specifying anything else that the categorical as such Learn1_1n_largest=removecats(Learn1_1n_largest). The full solution to my first question is:



        variable.group={'one','three','four','one','three','four','two','three','four','one','three','four','one','three','four','one','three','four', ...
        'one','three','four','one','three','four','one','three','four','one','three','four'}
        Group=categorical(variable.group)
        summary(Group)
        figure,histogram(Group),title('Summary Group')
        Group_tabulated = tabulate(Group)
        idx_largest=cell2mat(Group_tabulated(:,2))>3
        Group_to_display=Group_tabulated(idx_largest,1)
        Learn1_1n_largest=Group(ismember(Group,Group_tabulated(idx_largest,1)))
        figure,histogram(Learn1_1n_largest),title('Summary Group largest only')
        Learn1_1n_largest=removecats(Learn1_1n_largest)
        figure,histogram(Learn1_1n_largest),title('Summary Group largest only')


        I would be glad if anyone has the solution of my second question, as I hope that there would be a simpler solution without having to use both categorical & tabulate.



        Thanks!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 23:42









        NicoNico

        488




        488
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443745%2fplotting-group-variable-excluding-some-categories-based-on-condition%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]