Announcement

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

  • Creating distinguishable lines for folks who are colorblind when using graph twoway line


    Hi everyone.

    I would love to know how to create different lines by pattern. Below is my dataset.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(admission_year Type_1 Type_2 Type_3 Type_4)
    1  .2255541 .14637904  .1835391      .125
    2 .04302477  .1494607  .1654321 .04166667
    3  .2346806 .16640987  .2436214 .24621212
    4  .1642764 .08474576 .15226337 .24810606
    5 .19035202  .1725732  .1876543 .23958333
    6 .14211212 .28043142 .06748971 .09943182
    end


    I used the following code to graph my data.

    Code:
    graph twoway line Type_1 Type_2 Type_3 Type_4 admission_year, clwidth(thick) clcolor(yellow red green blue) title("Admission by Year") subtitle("2012-2018 cohort") legend( order(1 "Type_1" 2 "Type_2" 3 "Type_3" 4  "Type_4")) ylabel(0(.1).5, angle(horizontal)) ytitle("Percentage") xtitle("Year")
    Next, I tried to use the msymbol option to distinguish different lines by pattern. Currently, the lines are distinguished based on color but I fear folks who are colorblind may not see the differences. As a result, I ran the following line of code:

    Code:
    graph twoway line Type_1 Type_2 Type_3 Type_4 admission_year, clwidth(thick) clcolor(yellow red green blue) title("Admission by Year") subtitle("2012-2018 cohort") legend( order(1 "Type_1" 2 "Type_2" 3 "Type_3" 4  "Type_4")) ylabel(0(.1).5, angle(horizontal)) ytitle("Percentage") xtitle("Year"), msymbol(D, T, X, S)
    However, the code doesn't run. Any suggestions would be greatly appreciated. Thank you.

  • #2
    Code looks fine, just a few unnecessary commas. Try this:

    Code:
    graph twoway line Type_1 Type_2 Type_3 Type_4 admission_year, clwidth(thick) clcolor(yellow red green blue) title("Admission by Year") subtitle("2012-2018 cohort") legend( order(1 "Type_1" 2 "Type_2" 3 "Type_3" 4  "Type_4")) ylabel(0(.1).5, angle(horizontal)) ytitle("Percentage") xtitle("Year") msymbol(D T X S)
    Although I don't see the point of the -msymbol- given that this is a line graph. Note the advice in help line:

    Code:
    line, while it allows you to specify the marker_option msymbol(), ignores its setting.

    Comment


    • #3
      Hi Ali, Thanks for responding. Your updated code runs but as you mentioned, the msymbol option doesn't do anything. Is there an alternative way to differentiate the four different lines created by your code? For example, is there a way to make one line with diamonds, another line with triangles, another line with X's, and another line with squares? Right now, someone who is colorblind won't be able to distinguish the colors.

      Comment


      • #4
        You can turn it into a connected scatter:

        Code:
        graph twoway scatter Type_1 Type_2 Type_3 Type_4 admission_year, clwidth(thick) clcolor(yellow red green blue) title("Admission by Year") subtitle("2012-2018 cohort") legend( order(1 "Type_1" 2 "Type_2" 3 "Type_3" 4  "Type_4")) ylabel(0(.1).5, angle(horizontal)) ytitle("Percentage") xtitle("Year") msymbol(D T X S) c(l l l l)

        Comment


        • #5
          Thank you Ali. This is exactly what I was looking for. You're amazing. I appreciate you so much.

          Comment


          • #6
            Also see this Stata Journal article presenting schemes that allow for people with color vision deficiency: https://journals.sagepub.com/doi/pdf...867X1701700313



            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              See also https://www.statalist.org/forums/for...ailable-on-ssc and use mycolours as a search term in this forum to find examples of its use.

              Comment

              Working...
              X