Announcement

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

  • Color by group scatter plot

    I want to plot multiple scatter plots upon grouping them by category, here by region. However, I want to be able to arbitrarily change the line color and marker of any of the individual graphs, whether as measured by the graph position, the subset of the data (i.e., region == "West")...etc. For example, here the color line is orange and the marker is o, but how would I go about setting marker(+) and color(green) for the subplot where region == "West" ?


    Code:
    sysuse census, clear
    
    scatter pop divorce, by(region, ixaxes) sort connect(l) msymbol(o) ytitle("") color(orange)
    Thanks in advance!

  • #2
    See the command sepscatter from SSC: https://www.statalist.org/forums/for...lable-from-ssc. Otherwise, you can do the following:

    Code:
    sysuse census, clear
    local colors green orange blue red
    local symbols oh + D T
    separate pop, by(region) veryshortlabel
    separate divorce, by(region) veryshortlabel
    local command
    forval i=1/4{
        local command `command' scatter pop`i' divorce`i', sort connect(l) lc(`=word("`colors'", `i')') lp(solid) mc(`=word("`colors'", `i')') ms(`=word("`symbols'", `i')') ||
    }
    set scheme s1mono
    twoway `command', by(region, ixaxes leg(off) note(""))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	32.2 KB
ID:	1726157

    Last edited by Andrew Musau; 05 Sep 2023, 22:31.

    Comment


    • #3
      More on sepscatter

      Code:
      sysuse census, clear
      
      sepscatter pop divorce, separate(region) by(region, ixaxes note("") legend(off)) ///
      sort connect(l ..) msymbol(o) ytitle("") mcolor(red blue black magenta) lcolor(red blue black magenta)

      Comment


      • #4
        This is helpful, thank you very much Andrew Musau and Nick Cox !

        Comment

        Working...
        X