Announcement

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

  • colour coding in two-way dropline plot

    Hello,
    I am trying to distinguish droplines in a two-way dropline plot using different colour codes based on a categorical variable. Please note that I have different number of droplines in each category. Is it possible to do it in Stata?

    Thanks in advance for your response and support.
    Last edited by Mamun Huda; 07 Aug 2019, 04:54.

  • #2
    Yes, that is likely to be possible. separate is likely to be the key. To get precise advice you'll need to give your exact command and ideally a data example, neither of which is yet evident.

    Comment


    • #3
      Many thanks, Nick for your kind response.

      I will explore the "separate" key. However, I am also sending you my example dataset:

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input byte(region event) int month double index
      1 1 101 -.04456543
      1 1 102 -.22366977
      1 1 103 -.18224127
      1 1 104 -.18520155
      1 1 105 -.25422327
      1 1 106 -.03274019
      1 1 107   -.214101
      1 1 108 -.15150441
      1 1 109 -.05893304
      1 2 110 -.17668299
      1 2 111  .03202023
      1 2 112 -.07304322
      1 2 113 -.18920047
      1 2 114  -.0293457
      1 2 115 -.07255485
      1 2 116 -.10823589
      1 2 117  .02739052
      1 2 118 -.16033876
      1 3 119 -.14558274
      1 3 120 -.26880398
      1 3 121 -.10420506
      1 3 122  .04819746
      1 3 123  -.1582941
      1 3 124 -.07386343
      1 3 125 -.20657758
      1 3 126 -.16347356
      1 3 127 -.14267572
      1 4 128 -.20825162
      1 4 129  -.1708047
      1 4 130 -.11546738
      1 4 131  -.1311501
      1 4 132 -.13549459
      1 4 133 -.22564544
      1 4 134   .0210928
      1 4 135 -.00756734
      1 4 136 -.02268052
      1 4 137  -.1559068
      1 4 138 -.13051796
      1 4 139 -.13820574
      1 4 140 -.13526144
      1 4 141 -.05863849
      1 4 142  .00654885
      1 4 143 -.18984016
      1 4 144  -.1525872
      1 4 145 -.22168383
      1 4 146 -.12905128
      1 4 147 -.09187518
      1 1 148 -.04403891
      2 4 101 -.02632621
      2 4 102 -.07098256
      2 4 103 -.35597657
      2 4 104 -.22720844
      2 4 105 -.19867589
      2 4 106 -.13407439
      2 4 107 -.34761308
      2 4 108 -.29313611
      2 1 109 -.29486544
      2 1 110 -.18954702
      2 1 111 -.08406134
      2 1 112 -.17567455
      2 1 113 -.26873224
      2 1 114 -.05506746
      2 1 115 -.10025514
      2 1 116 -.29882877
      2 1 117 -.24819362
      2 1 118  -.2640195
      2 1 119 -.23581635
      2 1 120 -.36479868
      2 1 121 -.35368169
      2 1 122  .06226837
      2 2 123 -.18890692
      2 2 124 -.30127199
      2 2 125 -.23595627
      2 2 126  -.2606628
      2 2 127 -.23865505
      2 2 128 -.26654745
      2 2 129 -.42581543
      2 2 130  -.2620678
      2 2 131 -.25116891
      2 2 132 -.18500453
      2 2 133 -.23495972
      2 2 134  .07698295
      2 2 135 -.14358356
      2 2 136 -.13876035
      2 2 137 -.15299878
      2 2 138 -.23099192
      2 2 139 -.23454866
      2 3 140 -.36762659
      2 3 141 -.17897339
      2 3 142 -.09265568
      2 3 143  -.1954482
      2 3 144   -.310174
      2 3 145 -.25596743
      2 3 146  -.2285826
      2 3 147 -.21706971
      2 3 148 -.14608445
      end
      my code was:

      twoway dropline index month, hori xline(0) by(region)

      to generate a horizontal dropline plot with two panels (by region). Here I would like to highlight (colour code) different dropline group by the variable "event" in my dataset.

      Thanks again.

      Comment


      • #4
        Thanks for your code and data example. I did this:

        Code:
        set scheme s1color 
        
        separate index, by(event) veryshortlabel 
        twoway  dropline index1 month, yline(0) ///
             || dropline index2 month,          ///
             || dropline index3 month, by(region, col(1) note("")) /// 
        ytitle(unexplained index) xtitle("") legend(row(1)) yla(0 "0" 0.2 -0.2 -0.4, format("%02.1f") ang(h)) /// 
        xtick(95.5(12)155.5, tlength(*2)) xla(101.5 "1968" 113.5 "1969" 125.5 "1970" 137.5 "1971" 149.5 "1972", tlength(*0.2) tlc(none))
        On your question see also https://www.stata-journal.com/sjpdf....iclenum=gr0023 on separate, particularly the otherwise undocumented veryshortlabel option.

        I dropped the horizontal option, which seems odd for this kind of data. It's your graph and you can put it back.

        Some other technique shown, for which see also https://www.stata-journal.com/sjpdf....iclenum=gr0030

        Click image for larger version

Name:	dropline.png
Views:	1
Size:	28.4 KB
ID:	1511358


        Comment


        • #5
          #4 I left out index4 from the graph code. That was just a mistake.

          Comment


          • #6
            Hi Nick,

            Thank you so much for your help, and sharing the code and links. It helps me to solve my problem.

            Thank you once again!



            Comment

            Working...
            X