Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Single legend for a combined graph

    Hello,

    I am trying to combine 6 separate graphs, all have the same legends so I am trying to have only one legend for the combined graph. I tried using the grc1leg command but it keeps saying "class key not found". I would appreciate some help with this.

    Thank you

  • #2
    I think you need to show your exact syntax. A data example would also help. It is also very likely that there is a much simpler way to get your graph.

    Comment


    • #3
      Hi Nick,

      This is the syntax:
      gr combine 1.gph 2.gph 3.gph 4.gph 5.gph 6.gph
      This gives me a combined graph of 6, however, each of them has a legend. The legend is the same for each so I want only 1 for the whole thing.

      Comment


      • #4
        Use -grc1leg- written by Vince Wiggins. Install it first (if not installed already) by typing in Stata command line -findit grc1leg- and click the link (grc1leg from http://www.stata.com/users/vwiggins) for installation. Once done, the code is simple:

        Code:
        grc1leg graphnames
        Also see the help file for further options.
        Roman

        Comment


        • #5
          #3 Sure, but it's the grc1leg command that isn't working. Otherwise you are not adding any information to #1. I find that often when people are trying to combine several graphs, they have missed the fact that a by() option will do what they want in the first place.

          Comment


          • #6
            Apologies, it was my mistake to overlook that the original poster has already used -grc1leg-. @Vikash arya: You said you used -grc1leg- which is giving you error message but provided the codes for -gr combine- which is a Stata built-in command and a different one than -grc1leg- . Please note, as per the forum rules for posting, you are expected to provide exact commands you used.
            Roman

            Comment


            • #7
              Hi Roman,

              Apologies but I thought that since grc1leg is not working, I might be able to get a way through gr combine command. Anyways, here is the grc1leg command and the error message I get when I run it:

              grc1leg 1.gph 2.gph 3.gph 4.gph 5.gph 6.gph
              class key not found
              class key not found
              class key not found
              class key not found

              r(4010);

              end of do-file

              r(4010);

              Comment


              • #8
                You are still not showing the full commands. It is possible that you used different names to save the graphs and not referring them properly while combining. Without looking at your full codes it is difficult to suggest where the problem started. My wild guess will be your graph names being numeric. It may cause problem. Try with alpha-numeriec names to the graphs i.e. m1, m2 etc. instead numerical names. If doesn't work, please provide your full codes and before anything, Please read through the forum rules.
                Roman

                Comment


                • #9
                  Hi Roman,

                  I used the "play" option on the graphs. I made two graphs without the play option and they seem to combine with the grc1leg command with a single legend. So I guess I will create all the graphs again without the play option and then it should be fine. Thank you for your help.

                  Comment


                  • #10
                    I cant get grc1leg2 to work either. Specifically with two pie charts. I try the command, followed by graph names as confirmed in directory (or by the whole path) it returns "class key not found" repeated four times, exactly like shown above and in https://www.stata.com/statalist/arch.../msg01189.html

                    The program works regularly with other graphs. There are incidentally 4 pies in each of these particular graphs, and I suppose the program cannot find something it is looking for. The graphs use default settings for everything, so it's not a nonstandard colour or something of that sort, and nowhere the string "key" is mentioned. It's not spaces, dashes, underscores or so forth in names, based on few tests

                    grc1leg2 ///
                    "C:\Users\
                    [whole path]\pies_saliva.gph" ///
                    "C:\Users\
                    [same whole path as above]\pies_blood.gph"
                    class key not found
                    class key not found
                    class key not found
                    class key not found
                    r(4010);


                    or

                    graph dir, memory
                    Graph pies_blood pies_saliva

                    grc1leg2 pies_blood pies_saliva
                    class key not found
                    class key not found
                    class key not found
                    class key not found
                    r(4010);



                    If I find time I'll try to recreate the problem with example data. In the meanwhile, suggestions?
                    Many tanks

                    Comment


                    • #11
                      Stata has now fixed the problem reported above that was preventing -graph combine- from working properly in Stata 16 and therefore breaking Vince Wiggins' -grc1leg- and my -grc1leg2-. Inspired by Stata's bug fix, I have updated -grc1leg2- to version 1.31. The updated help file compares and demonstrates three ways of constructing a multi-panel graph with a single legend. The first approach covered is to use the -graph- command with the -by()- and -at()- options. It is often the best choice if the only difference across the panels is the value of a categorical variable, which can serve as the -by()- variable. The second approach is to use Stata's -gr combine- command with approriate options on the component graphs, followed by tweaks with Stata's -graph editor- as necessary. The third way is to use -grc1leg- or my -grc1leg2- command.

                      In addition to allowing all Stata's -graph combine- options, grc1leg2:
                      (a) suppresses the display of the legends on the component graphs;*
                      (b) creates and positions a legend in the combined graph by borrowing the legend previously defined for one of the user-selected component graphs;*
                      (c) optionally suppresses the x-titles or the y-titles of the component graphs, borrowing them for the combined graph;
                      (d) optionally suppresses the main title of the component graphs, borrowing it for the main title of the combined graph;
                      (e) optionally applies fine adjustments to several characteristics of the single legend and/or the borrowed titles;
                      (f) facilitates the calibration and coding of the fine adjustments using the dialog invoked with "db grc1leg2".
                      (g) optionally creates a combined graph with no legends at all.
                      * Capabilities inherited from -grc1leg-.

                      Personally, I find that using the -grc1leg2- dialog is a big help tweaking the multi-panel graph's appearance, saving me time and frustration. Please post bug reports or send them to me here: MOver@CGDev.org.

                      If -search grc1leg2- does not discover the program for you, you can "describe" it with:
                      net describe grc1leg2, from("http://digital.cgdev.org/doc/stata/MO/Misc")
                      or install it with:
                      net install grc1leg2, from("http://digital.cgdev.org/doc/stata/MO/Misc")
                      To download the example DO file into your current working directory, type:
                      net get grc1leg2, from("http://digital.cgdev.org/doc/stata/MO/Misc")



                      Comment

                      Working...
                      X