Announcement

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

  • How to color arrow graph (twoway pcarrow) lines based on the value of another variable?

    I have coded up an arrow graph that I would like to further alter by coloring the individual arrows based on the value of another variable (diff_neg). I know that Nick Cox wrote a package called sepscatter, but I am not sure that will work in this instance. Does anyone have any suggestions?

    The code for my arrow graph is the following:
    Code:
    graph twoway (pcarrow Grade2a Perc_F1M Grade2a Perc_F2M, msize(small))  ///
        (scatter Grade2a mid, msymbol(i) mlabel(Term_a) mlabsize(small) mlabpos(12) mlabcolor(black)) , ///
        legend(off) ytitle("Grade Span") ylabel(3 "2nd-3rd" 4 "3rd-4th" 5 "5th-6th" 6 "6th-7th" 7 "7th-8th") ///
        xtitle("Percentile Rank") xscale(range(60 80)) xlabel(60(5)80)
    Leading to the graph:
    Click image for larger version

Name:	Arrow Plot Test One Group.png
Views:	1
Size:	157.9 KB
ID:	1599669

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(Perc_F1M Perc_F2M) float(Grade2a mid) str3 Term_a float diff_neg
    75.4 76.3 3.05 75.85 "F19" 0
    76.1 73.5  2.8  74.8 "F20" 1
    76.2 78.8 4.05  77.5 "F19" 0
    76.2 73.3  3.8 74.75 "F20" 1
    78.9 79.7 5.05  79.3 "F19" 0
    78.8 75.1  4.8 76.95 "F20" 1
    78.6 76.9 6.05 77.75 "F19" 1
    79.7 73.7  5.8  76.7 "F20" 1
    74.4 78.3 7.05 76.35 "F19" 0
    76.9 77.2  6.8 77.05 "F20" 0
    end
    Last edited by Erik Ruzek; 24 Mar 2021, 14:45. Reason: Added Nick Cox tag and edited subject

  • #2
    One option that came to mind after I posted my question (of course!) is to include separate twoway statements for diff_neg==0 and for diff_neg==1, as such:
    Code:
    graph twoway (pcarrow Grade2a Perc_F1M Grade2a Perc_F2M if diff_neg==0, msize(small) lcolor(navy) mcolor(navy))  ///
        (scatter Grade2a mid if diff_neg==0, msymbol(i) mlabel(Term_a) mlabsize(small) mlabpos(12) mlabcolor(black)) ///
        (pcarrow Grade2a Perc_F1M Grade2a Perc_F2M if diff_neg==1, msize(small) lcolor(red) mcolor(red))  ///
        (scatter Grade2a mid if diff_neg==1, msymbol(i) mlabel(Term_a) mlabsize(small) mlabpos(12) mlabcolor(black)) , ///
        legend(off) ytitle("Grade Span") ylabel(3 "2nd-3rd" 4 "3rd-4th" 5 "5th-6th" 6 "6th-7th" 7 "7th-8th") ///
        xtitle("Percentile Rank") xscale(range(60 80)) xlabel(60(5)80)
    Leading to:
    Click image for larger version

Name:	Arrow Plot Test One Group.png
Views:	1
Size:	157.7 KB
ID:	1599674

    Comment


    • #3
      You could rewrite sepscatter (SSC) to do this, but that's it. An easier path if to note that separate could be used to define separate outcome variables. one each for each distinct arrow colour.
      Last edited by Nick Cox; 24 Mar 2021, 17:08.

      Comment

      Working...
      X