Announcement

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

  • Two Colours in XMLA option?

    Code:
    clear
    
    input int date float gnp96
    28 3631.6
    29 3644.5
    30   3672
    31 3703.1
    32 3757.5
    33 3818.3
    34 3841.6
    35 3861.8
    36 3906.8
    37   3915
    38 3937.8
    39 3922.9
    40   3922
    41 3922.3
    42 3961.3
    43   3931
    44 4027.3
    45   4042
    46 4064.7
    47 4072.9
    end
    
    format %tqq date
    set scheme s1color 
    
    #delimit ;
    
    tw connected gnp96 date
    , 
    
    xmla(28/47, tlength(0)) 
    xtick(27.5(4)47.5, tlength(*5)) 
    xla(29.5(4)45.5, format(%tqCCYY) tlength(*2) tlcolor(none)) 
    xtitle("")
    
    ;
    #delimit cr
    A few years ago, Nick Cox helped me understand how to correctly label the X-axis (following the example he provided). Now I’m wondering—and I’ve been trying—whether it’s possible to have a bit more control over the xmla subcommand. For example, I’d like to change the color of the last four labels that appear in xmla.

    I tried following the logic used in this post: Is it possible to have labels in two or more colors in Stata? - Statalist, but it didn’t work.

    My question is it possible to do the same thing they did in that post, por does this option simply not offer that level of control?

    Best regards.

  • #2
    Minor ticks and labels ({y|x|t|z}mlabel) and major ticks and labels ({y|x|t|z}label) work in much the same way. You need to separate the values and add options to specify more than one label color. Your title correctly refers to -xmlabel()- as an option, but in your description you refer to it as a subcommand, which it is not.

    Code:
    clear
    
    input int date float gnp96
    28 3631.6
    29 3644.5
    30   3672
    31 3703.1
    32 3757.5
    33 3818.3
    34 3841.6
    35 3861.8
    36 3906.8
    37   3915
    38 3937.8
    39 3922.9
    40   3922
    41 3922.3
    42 3961.3
    43   3931
    44 4027.3
    45   4042
    46 4064.7
    47 4072.9
    end
    
    format %tqq date
    set scheme s1color 
    
    #delimit ;
    
    tw connected gnp96 date
    , 
    
    xmla(28/43, add tlength(0) labcolor(black)) 
    xmla(44/47, add custom tlength(0) labcolor(red))
    xtick(27.5(4)47.5, tlength(*5)) 
    xla(29.5(4)45.5, format(%tqCCYY) tlength(*2) tlcolor(none)) 
    xtitle("")
    
    ;
    #delimit cr
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	38.1 KB
ID:	1783355

    Comment


    • #3
      Thanks Andrew Musau, I appreciate your quick response.

      Comment


      • #4
        I have a question. I’ve already looked at the ‘add’ and ‘add custom’ options, but now I’m wondering—could the same be done for the year labels and the dividing lines following your logic Andrew Musau ? Thank you so much.

        Comment


        • #5
          It should be easy enough to check. See highlighted.

          Code:
          clear
          
          input int date float gnp96
          28 3631.6
          29 3644.5
          30   3672
          31 3703.1
          32 3757.5
          33 3818.3
          34 3841.6
          35 3861.8
          36 3906.8
          37   3915
          38 3937.8
          39 3922.9
          40   3922
          41 3922.3
          42 3961.3
          43   3931
          44 4027.3
          45   4042
          46 4064.7
          47 4072.9
          end
          
          format %tqq date
          set scheme s1color 
          
          #delimit ;
          
          tw connected gnp96 date
          , 
          
          xmla(28/43, add tlength(0) labcolor(black)) 
          xmla(44/47, add custom tlength(0) labcolor(red))
          xtick(27.5(4)39.5, add tlength(*5) tlcolor(black)) 
          xtick(43.5 47.5, add custom tlength(*1) tlcolor(red)) 
          xla(29.5(4)41.5, add  format(%tqCCYY) tlength(*2) tlcolor(none)) 
          xla(45.5, add custom format(%tqCCYY) tlength(*1) tlcolor(none) labcolor(red)) 
          xtitle("")
           
          ;
          #delimit cr
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	38.7 KB
ID:	1783365

          Comment


          • #6
            Thank you very much, I tried, but I was doing it wrong.

            I really appreciate it Andrew Musau

            Comment

            Working...
            X