Announcement

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

  • How to incorporate xline into a legend?

    Hi all

    I've created a twoway scatterplot and added four vertical lines representing quintile cut-offs. I have two queries I'm hoping someone can help me with: (1) Is there a way to incorporate these reference lines into a legend? and (2) can the quintile lines be 'brought to the front' so they sit on top of the bubbles, currently, they 'sit behind' they bubbles. I'm using Stata 12.1 and here is the code I've written:

    twoway (scatter y x [fweight=z], msymbol(O) mcolor(gray) msize(*1.2)) ///
    (scatter y x [fweight=z], msymbol(Oh) mlcolor(white) msize(*1.2)), xline(5 9 14 22, lp(dash) lcolor(gs3)) ///
    xtitle("XYZ") ytitle("XYZ") xlabel(0(10)70)

    Many thanks in advance.
    Catherine

  • #2
    In my view you shouldn't even want to do this, namely to add four more elements to the legend. Legends are at best a necessary evil, as they impose a burden on the reader, of being expected to go back and forth between legend and graph to understand what is being shown. Vertical lines should be annotated on the graph. Using a second x axis can be a natural way to do this.

    xlines are intended to be background or reference lines; to subvert that you need to plot data invented for the purpose. This code

    Code:
     
    sysuse auto, clear
    scatter mpg weight
    scatter mpg weight || scatteri 10 2500 42 2500 , recast(line)
    indicates minimal technique. Note that with this device you get your wish, an addition to the legend, but I would still advise against it. Your readers should thank you for axis annotations (use a top axis, for example).

    Comment


    • #3
      Thanks for your quick reply Nick. I hadn't thought about the burden for the reader and totally take your point re adding more elements to the legend and instead annotating the graph for the quintiles, I'm going to pursue the later now. Many thanks, Catherine

      Comment

      Working...
      X