Announcement

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

  • graph-legend order: how to lay 5 legends in first column, while 2 legends in the second column?

    Dear all,

    I had graphed two categories of y (two y-axes) towards the same x in one graph. The left y-axis has 5 scatter plots, while the right y-axis has 2 scatter plots. I want to separate the legend into two columns, with the first column displaying the left y-axis plots and the second column displaying the right y-axis plots.

    I tried to use legend(order (1 2 3 4 5 6 7)...), but it will generate 4 legends in the first column and 3 legends in the second.

    Great thanks if you have some suggestions.

    Best,
    Haiyan


  • #2
    If you are ok with row rather than column orientation of legend you can try the following code at the end of the command you are using.

    Code:
    legend(pos(6) col(5))

    Comment


    • #3
      Code:
      set obs 200
      set seed 07242021
      gen catvar= runiformint(1,7)
      set scheme s1mono
      gr bar, over(catvar) asyvars leg(order(1 6 2 7 3 8 4 9 5) col(2)) saving(gr1, replace)
      *OR EVEN
      gr bar, over(catvar) asyvars leg(order(1 8 2 9 3 6 4 7 5) col(2) holes(2 4)) saving(gr2, replace)
      gr combine gr1.gph gr2.gph
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	45.8 KB
ID:	1620398

      Last edited by Andrew Musau; 24 Jul 2021, 01:08.

      Comment


      • #4
        The examples are aimed at the question, which is as it should be, but I wouldn't use a legend at all in these cases!

        Comment


        • #5
          Great thanks to @ Andrew Musau ! That's exactly what I want. So happy to get advice here.

          Also, many thanks to @ Tarun Choudhary and @ Nick Cox for your kind reply. In my case, legends are needed cause different sources of data are used, which should be declared clearly.

          Comment

          Working...
          X