Announcement

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

  • Scatter: different marker and marker label color for a observation

    I am trying to scatter poverty estimates for 50 countries against GDP per capita. Is there any way to use a different marker and marker label color for a country to make it easier for readers to see where the country of interest is in the graph?

    I tried using:

    scatter value gdppccp2019, mlabel(country3) mlabv(pos2) mlabsize(small) mcolor(blue) msize(vsmall) mlabcolor(blue if country3=="AFG")

    but the label color is blue for all countries, not only for AFG.


  • #2
    You can do it, but it will end up being a mess. Beyond a couple of countries, different colors and markers will not help much in differentiating the countries. Here is a way with 5 groups.

    Code:
    webuse grunfeld, clear
    keep if company<=5
    local symbols square triangle diamond circle plus
    separate invest, by(company)
    separate mvalue, by(company)
    local myscatter
    forval i=1/5{
        local myscatter "`myscatter' (scatter invest`i' mvalue`i', msymbol(`=word("`symbols'", `i')'))"
    }
    set scheme s1color
    tw `myscatter'
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	20.0 KB
ID:	1600971

    Comment


    • #3
      #1 what is often done is to use marker labels so that the reader can locate a specific country that he/she is interested in. Here is an example.

      Code:
      sysuse census, clear
      scatter marriage pop, mlab(state2)
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	26.6 KB
ID:	1600981




      Here, the states at the bottom left hand side of the graph are not visible. As marriages and population are necessarily positive integers, a log scale may help.

      Code:
      sysuse census,clear
      gen logmarriage= ln(marriage)
      gen logpop= ln(pop)
      scatter logmarriage logpop, mlab(state2)
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	25.1 KB
ID:	1600982

      Comment


      • #4
        See also https://www.statalist.org/forums/for...lable-from-ssc

        In this case I would probably start with something like


        Code:
        scatter value gdppccp2019 , ms(Oh) || scatter value gdppccp2019 if country3 == "AFG", ms(O)  mlabel(country3) mlabsize(small) mlabcolor(blue)
        and indeed -- having drawn many similar graphs myself -- I would feel compelled to show GDP per head on a log scale.

        Given many, many countries, leaving out the marker symbols and just putting marker labels at position 0 is often a step towards reducing a horrible mess.

        Comment


        • #5
          Thanks a lot Andrew and Nick. I took Nick's suggestion as I have only one country to highlight, with this code.

          twoway scatter value gdppccp2019 if country3!="AFG", mlabel(country3) mlabv(pos2) mlabsize(vsmall) mcolor(black) msize(vsmall) mlabcolor(black) || scatter value gdppccp2019 if country3 == "AFG", ms(O) mlabel(country3) mlabsize(medium) mcolor(blue) mlabcolor(blue)

          Comment


          • #6
            https://www.stata-journal.com/sjpdf....iclenum=gr0023 contains one of many examples of suppressing marker symbols and showing marker labels at the same positions. The principle is even more important with two or three-letter abbreviations, let alone longer names.

            Comment

            Working...
            X