Announcement

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

  • Changing color of the symbol when colorvar() in use

    Dear all,

    I am using twoway scatter to graph the relationship between Gini and GDP for five regions in two years. And I am using the new colorvar() function because I want to distinguish between the year and the region.
    The goal is to have each region in one color, and two symbols represent different years.
    However, the problem is that year legend has the same color as the first region, which might be confusing. And I want to change it to black.
    Does anyone know how to do it?

    My code
    Code:
    twoway (scatter Gini GDP if year==2010, colorvar(region) colordiscrete colorrule(phue) coloruseplegend msize(medium) msymbol(circle)) ///
           (scatter Gini GDP if year==2018, colorvar(region) colordiscrete colorrule(phue) coloruseplegend msize(medium) msymbol(diamond)), ///
           zlabel(, valuelabel) legend( lab(1 "2010") lab(2 "2018") pos(6) row(1) )
    And in the attached graph, you can see that the symbol of the year legend is in the same color as the first region.

    Thank you very much in advance for the help!

    Graph.png
    Last edited by Ivy Gong; 18 Aug 2023, 04:32.

  • #2
    I have solved it! I added two "ghost" plot to make it work. Here attaches my code. If anyone has a better solution, please share!

    Code:
    twoway (scatteri . .  if year==2010, mcolor(black)  msymbol(circle)) (scatteri . . if year==2018, mcolor(black) msymbol(diamond)) ///
           (scatter Gini GDP if year==2010, colorvar(region) colordiscrete colorrule(phue) coloruseplegend msize(medium) msymbol(circle)) ///
           (scatter Gini GDP if year==2018, colorvar(region) colordiscrete colorrule(phue) coloruseplegend msize(medium) msymbol(diamond)), ///
           zlabel(, valuelabel) legend( order (1 "2010" 2 "2018") pos(6) row(1))

    Comment

    Working...
    X