Announcement

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

  • Control individual legend key symbol/color size?

    Is there a way to control the size or marker type of *individual* keys in graph legends? Due to my organization's style guide, I have a graph with items that look too similar in the legend. Can I make a single color swatch appear more like a line rather than a uniformly sized rectangular color swatch?

    Roughly speaking my graph is made like this:
    Code:
    sysuse sp500, clear
    twoway area high date || bar open date
    I've read legend_options and thought legend(symysize()) might be able to help, but it seems to control all the legend symbols at once.
    That is, none of the following work--they don't all throw errors, but they don't accomplish the goal of different sized/shaped legend keys.
    Code:
    twoway area high date || bar open date, legend(symysize(5 1))
    twoway area high date, legend(symysize(5)) || bar open date, legend(symysize(1))
    twoway area high date, legend(symysize(5, 1)) || bar open date
    twoway area high date, legend(symysize(5) symysize(1)) || bar open date

    I know the default blue and red in my example code aren't hard to distinguish, but please imagine that I'm required to use fairly similar colors. You might reasonably suggest that I switch the second twoway type from bar to connected, but I'd like to keep them as area and bar if possible.

    Thanks,
    Garret

  • #2
    Here is one way using the undocumented gr_edit command:

    Code:
    twoway area high date || bar high date
    gr_edit .legend.plotregion1.key[2].ysz.editstyle 1
    Which produces

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	101.2 KB
ID:	1663213

    Comment


    • #3
      I've done something like this by adding a zero-length function to the twoway command. The gr_edit approach suggested in #2 is somewhat more elegant, however.
      Code:
      sysuse auto
      tw (scatter price mpg, mco(orange) leg(order(2) label(2 "Price"))) ///
         (function y=5000, ra(20 20) lco(orange) lw(*5) lpat(solid))

      Comment


      • #4
        Excellent, thanks Ali Atia, your solution worked quite well.

        Comment

        Working...
        X