Announcement

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

  • Grid of pie graphs with titles along the top and left side

    I have a 6X8 grid of pie graphs created with graph pie and graph combine. I would like to label (with one or two layers of text, depending on the particular row/column) the top and left side of the combined graph. I have tried the following things:
    1)I created the graphs on the top and left edge of the grid with the appropriate titles, but this shrinks the size of those pie graphs relative to the others when combined.
    2)I used fxsize and fysize to manually manipulate the graphs with titles. I can get it pretty close, but it is somewhat clugey and it requires a lot of trial and error. It also doesn't solve the problem that there are some titles that I want to span two graphs.
    3)I have tried using the title options in graph combine and I can't get everything labeled exactly where I want it without a lot of trial and error.
    4)I tried creating the top row and the left row independently first and doing a more complicated combine, but that had some other disadvantages (I am also trying to separate parts of the combined graph with outlines) and was hard to get the sizing right (although that might be because of my expertise with graph combine
    5)I can, of course, use the graph editor.
    Because I try to do everything in an automated fashion (I am doing multiple of these in slightly different contexts), I would prefer to have a better solution than some of the more manual approaches that I have tried.

    Thanks,
    Jeff

  • #2
    You were not satisfied with the l1title l2title t1title and t2title options described in help title_options? Not even with positioning suboptions?

    Comment


    • #3
      I think I understand what Jeffrey is confronting, because I've been there myself. The twist is pie charts, in his case, so I'll talk about regular graph twoway plots.

      When I use graph combine to create a matrix of graphs, Stata wants to scale each graph by the same amount.

      But in a matrix of graphs - think of a scatterplot matrix - you don't want axis labels on every graph in the matrix, you typically want them along the vertical axes of the graphs in the leftmost column of the matrix and along the horizontal axes of the graphs in the bottommost row of the matrix. I find the easy way to do that is to appropriately label the particular graphs and then combine them.

      But in doing so, the graphs with labels have different proportions for the plot areas than do the graphs without labels, and the result is a matrix unequal-sized plots.

      This problem extends beyond graph labels to axis labels and the like. I want the matrix of graphs to have as little of the charting apparatus separating them as possible, migrating titles, axis labels, and the like to the periphery of the matrix of graphs. I can do this by applying them to the appropriate graphs, but that changes their layout in ways that graph combine doesn't seem to handle.

      It seems to me that graph combine needs an option to give each twoway plot (the plot area itself, exclusive of titles, axis labels, etc.) the same size, rather than each entire graph.

      I don't know how to accomplish this effectively. A few years on Statalist leads me to believe I may have once seen packages that assist with this, but I'm not able to find something at the moment.

      Comment


      • #4
        The approach that Dave suggests is the best that I got, but it still requires a bunch of fiddling to get the row and column titles aligned where I want them. It also is a little frustrating, because I am trying to make process automated for when I have different numbers of rows or columns and different complexities of labeling. I was hoping that there would be a magic factor that I could change the scaling to accommodate additional titles on the top and left rows.

        Comment


        • #5
          I have _fiddled_ in the past to achieve my combined graphs, agreed. I wonder if we can fix the graph regions of all graphs (help region_options) within a fixed xsize and ysize leaving the positioning of titles on the border graphs to not be so fiddly, to be where you expect them? But then I started reading the section "How graphs are constructed" and space is given to whatever is needed from the outside of the graph inward. I guess we need a reproducible example to work on.

          Comment


          • #6
            What about adding in empty title text to the plots in the middle of the combined graph, e.g., " "?

            Comment


            • #7
              This thread is innocent of any example data or code or graphs, contrary to advice in the FAQ, so I remain fuzzy on the details.

              I am guessing that the pie graphs refer to common or at least shared categories; otherwise the combined pie charts would just look like a miscellaneous medley.

              I'll throw out a suggestion that restructuring your data and then using by() is likely to give a much more civilised control of titles and so forth.

              Here's a minimal example.

              Code:
              clear
              set seed 2803 
              set obs 200 
              
              forval j = 1/9 { 
                 gen y`j' = runiformint(1, 5) 
              } 
              
              gen id = _n 
              
              reshape long y, i(id) j(which) 
              
              graph pie, over(y) by(which)
              The real example is perhaps much more complicated, but if so I'd suggest presenting it more directly.

              Comment


              • #8
                Here's an example of what I am suggesting

                Code:
                clear
                
                input sales marketing research development year
                 12 14 2 8 2002
                 13 15 3 5 2003
                 15    15 4 6 2004
                 12 10 2 7 2005
                 end
                
                // same size pies
                
                graph pie sales marketing research development ///
                    if year == 2002, name(g2002, replace) ///
                    legend(position(4) col(1)) ///
                    l1title("2002") t1title("2002") nodraw
                
                graph pie sales marketing research development ///
                    if year == 2003, name(g2003, replace) ///
                    legend(position(4) col(1)) ///
                    l1title(" ") t1title("2003") nodraw
                    
                graph pie sales marketing research development ///
                    if year == 2004, name(g2004, replace) ///
                    legend(position(4) col(1)) ///
                    l1title("2004") t1title(" ") nodraw
                
                graph pie sales marketing research development ///
                    if year == 2005, name(g2005, replace) ///
                    legend(position(4) col(1)) ///
                    l1title(" ") t1title(" ") nodraw
                
                graph combine g2002 g2003 g2004 g2005, name(same, replace)
                
                // different sized pies
                
                graph pie sales marketing research development ///
                    if year == 2002, name(g2002, replace) ///
                    legend(position(4) col(1)) ///
                    l1title("2002") t1title("2002") nodraw
                
                graph pie sales marketing research development ///
                    if year == 2003, name(g2003, replace) ///
                    legend(position(4) col(1)) ///
                    t1title("2003") nodraw
                    
                graph pie sales marketing research development ///
                    if year == 2004, name(g2004, replace) ///
                    legend(position(4) col(1)) ///
                    l1title("2004") nodraw
                
                graph pie sales marketing research development ///
                    if year == 2005, name(g2005, replace) ///
                    legend(position(4) col(1)) ///
                    nodraw
                
                graph combine g2002 g2003 g2004 g2005, name(different, replace)

                Comment


                • #9
                  If his solution is solved by an artificial by variable that would be excellent...I got the impression this was not the case. If he has different variables in different data sets, and yet the row and column titles are consistent, then this won't work is my guess.

                  Comment

                  Working...
                  X