Announcement

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

  • Labeling a single observation on a scatter plot.

    I looking at the relation between years of education and vaccine skepticism across countries. I want to label just one country, France. But am unable to. I tried labeling all countries on the graph and even that fails. The Country variable is a string variable. I'm not sure what's going on here.

    Code:
    reg Safety School_Years

    gen country1 = "France" if Country=="France"
    scatter Safety School_Years || lfit Safety School_Years, mlabel(country1) legend(off) ytitle("% not agreeing that vaccines are safe")

    *Labelling all countries - also failing
    scatter Safety School_Years || lfit Safety School_Years, mlabel(Country) legend(off) ytitle("% not agreeing that vaccines are safe")

  • #2
    Here is some technique, in the absence of a data example of yours:

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . sort price
    
    . l make in L
    
         +--------------+
         | make         |
         |--------------|
     74. | Cad. Seville |
         +--------------+
    
    . scatter price weight , ms(Oh) || scatter price weight in 74, ms(O) mc(red) mla(make) mlabcolor(red) scheme(s1color) legend(off) ytitle(Price (USD)) 
    
    .
    Click image for larger version

Name:	label_one_point.png
Views:	1
Size:	31.9 KB
ID:	1532521



    So here's a guess at code closer to what you wish

    Code:
     scatter Safety School_Years || lfit Safety School_Years || scatter Safety School_Years if country == "France", mlab(country)  legend(off) ytitle("% not agreeing that vaccines are safe")
    The main problem in #1 is there are no markers to label in lfit. The option belongs on a scatter call, but your || raise a wall that the mla() option can't cross.

    Comment


    • #3
      It is also possible to use the graph edit capability after the graph is created. This provides a great deal of flexibility. You can record and rerun your edits in case you need them on another graph.

      Comment

      Working...
      X