Announcement

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

  • Stata legend: make it larger and allow for more colors

    Hello everyone, I am trying to make a twoway line plot with many (more than 20) overlaid lines. I have two problems:
    1) At the moment the legend box is nearly a square, so it takes a lot of vertical space in the graph. How can I make it larger (more of a rectangular), so that it better exploits the space?
    2) Is there a way to make stata legend use more colors, so that two different lines are not colored in the same way?

    Thank you everyone in advance

  • #2
    20+ items in the legend and 20+ lines in one plot sounds like a recipe for disaster. Personally, I do not think that different colors will help much. Nonetheless, look at the -rows()- and -cols()- suboptions of -legend()-. For colors, changing scheme may help or you may need to explicitly specify the colors.

    Code:
    help legend_options

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      20+ items in the legend and 20+ lines in one plot sounds like a recipe for disaster.

      Code:
      help legend_options
      Sometimes unavoidable even though one cannot distinguish between all the lines, such as here:
      http://www.eurocrisismonitor.com/

      Comment


      • #4
        Originally posted by Eric de Souza View Post
        Sometimes unavoidable even though one cannot distinguish between all the lines, such as here:
        http://www.eurocrisismonitor.com/
        Yes, that's exactly what I'd like my plot to look like. I managed to deal with the legend size, but still cannot find how to include more colors than the default.

        Comment


        • #5
          We can't see what command you are using: you show precisely no syntax.

          But in one case of line varlist time if you want say 24 colours then you need to specify what you want with a lcolor() option specifying those colours.

          Comment


          • #6
            Originally posted by Nick Cox View Post
            We can't see what command you are using: you show precisely no syntax.

            But in one case of line varlist time if you want say 24 colours then you need to specify what you want with a lcolor() option specifying those colours.
            Thank you, I am doing a simple

            Code:
            twoway line varlist year, options
            So I guess your solution work, I just wanted to know if there wasn't a more automated way of doing this

            Comment


            • #7
              Well, you could write a program to automate colour choice for an arbitrary number of colours. I don't know that anyone has done that. But users may have written graph schemes that allow that. I haven't tried to monitor such schemes which are often announced outside Statalist.

              My own stance is that the best legend is none at all, but in various places I have tried to indicate alternatives to the awkward mix of multi-coloured spaghetti and bloated legend.

              https://www.stata-journal.com/articl...article=gr0080

              https://www.statalist.org/forums/for...e-on-ssc/page2

              The challenge to you is to post your data so that people like me who have other ideas can have their bluff called.

              Comment

              Working...
              X