Announcement

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

  • A Visualization Question: How to add labels for a tline in a scatter plot?

    Dear List-goers,

    I've got a scatter plot with X representing time and Y representing my variable of interest (wind power capacity). I have added two vertical lines indicating the passage of different kinds of policy programs for wind using Stata's tline command. How can I add a label for these lines, either in the plot area of under the X-axis?

    I've searched the UCLA site and the Stata help file, but I don't see a specific command or example. I'm attaching the plot I made with the labels added (e.g., RPS and 1603) using a graphics program. Is there a way to do this within Stata?

    Thank you in advance!

    -nick
    Attached Files
    Last edited by Nick Cain; 25 Aug 2014, 13:55.

  • #2
    Yes, you can use the tlabel() options.

    For example:
    Code:
    sysuse sp500
    scatter open date, tline(10may2001 , lp(dash) lc(black) )  tlabel(10may2001 "RSP" , add  labsize(*.75)) tline( 10nov2001 , lp(solid) lc(black) )  tlabel(10nov2001 "1603" , add  )
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	17.8 KB
ID:	180181
    Attached Files

    Comment


    • #3
      Dear Scott: Thanks! Your suggested code worked well, but the way I instantiated it, the labsize command seems to have affected all the X-axis labels.

      Is there a way to make the main X-axis elements appear as standard size and the line labels as .75? Or perhaps it would be cleaner to label these lines within the plot area instead -- but how can I add a label in that fashion?

      Thanks again!

      -nick

      Code:
      graph twoway (scatter mw yr) (lfit mw yr) (fpfit mw yr) if id==2, tline(2003, lcolor(gs10)) tlabel(2003 "RPS", add labsize (*.75)) ///
          tline(2009, lstyle(dot)) tlabel(2009 "1603", add labsize (*.75)) ///
          title("California Wind Capacity") ///
          ytitle("MW") ///
          xtitle("") ///
          legend(ring(1) pos(6) order(2 "Linear" 3 "Fractional Polynomial" )) ///
          graphregion(color(gs15)    ) plotregion(    color(white))
      Attached Files

      Comment


      • #4
        Nick:

        Please consider using your full real name, not "politicsearth", as an identifier.

        To get labels at different sizes, one trick is use minor labels as well. The fact that they are small by default is not a problem. Consider

        Code:
         
        sysuse sp500
        
        scatter open date, tline(10may2001 , lp(dash) lc(black) )  tmlabel(10may2001 "RSP" , add labsize(*1.25)) tline( 10nov2001 , lp(solid) lc(black) )  tmlabel(10nov2001 "1603" , add labsize(*1.25)) tla(, labsize(*.75))

        Comment


        • #5
          Hi Nick and Scott,

          After playing around with those label suggestions, I wasn't able to get the look I want.

          Is it possible to program call-out labels, as I created using an external graphics program (see attached)?

          Thanks for any suggestions!

          -nick

          Comment


          • #6
            Those extra labels could be simulated using arrows and boxed added text. I don't think they are available via a single option.

            Comment


            • #7
              I would like to come back to the question of Nick Cain (25 Aug 2014): "Or perhaps it would be cleaner to label these lines within the plot area instead -- but how can I add a label in that fashion?"
              Is there any way to do that? I have the problem that the axis label overlays the line label.

              Comment


              • #8
                Code:
                 
                help added text options

                Comment

                Working...
                X