Announcement

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

  • Formatting a scatter graph

    The code below produces the graph below. I'd like to make the following changes to the graph, but am unable to figure out how to:
    1. Remove the gray grid lines
    2. Move the years on the x-label lower
    3. Add “Mandate” under the first red line and “Platform” under the second red line
    4. Shade the region between the first and the second red line a light gray and the region after the second red line a darker gray
    Any help on this will be much appreciated!

    Click image for larger version

Name:	trendline.png
Views:	2
Size:	159.8 KB
ID:	1767616


    Code:
    
    *Code
    
    set scheme s1color
    
    su year, meanonly 
    local first = r(min)
    local last = r(max)
    
    forval y = `first'/`last' { 
        su mdate if year == `y', meanonly 
        local labelcall `labelcall' `r(mean)' "`y'"
        local tickpos = r(max) + 0.5 
        if `y' < `last' local tickcall `tickcall' `tickpos'
    }
    
    mac li 
    
    
    scatter one mdate,  ///
    ytitle("Number of teleconsults") yscale(range(0 .)) ylabel(#6, labsize(small) ///
    angle(horizontal) nogrid) ms(Oh) mc(black) xline(761 768) ///
    xtick(`tickcall',  tlength(*2)) ///
    xla(`labelcall', noticks labsize(small)) ///
     xtitle("Year" "", height(6)) graphregion(fcolor(white)) || lfit one mdate, legend(off) xli(`tickcall', lc(gs12))
    
    
    *Data
    input float(year month) long one byte(treatment1 treatment2) float mdate
    2020  7 1585 0 0 726
    2020  8 2460 0 0 727
    2020  9 2778 0 0 728
    2020 10 3284 0 0 729
    2020 11 3280 0 0 730
    2020 12 3262 0 0 731
    2021  1 2688 0 0 732
    2021  2 2849 0 0 733
    2021  3 2806 0 0 734
    2021  4 2517 0 0 735
    2021  5 4012 0 0 736
    2021  6 2665 0 0 737
    2021  7 2556 0 0 738
    2021  8 2618 0 0 739
    2021  9 2693 0 0 740
    2021 10 2247 0 0 741
    2021 11 2028 0 0 742
    2021 12 2217 0 0 743
    2022  1 2233 0 0 744
    2022  2 2224 0 0 745
    2022  3 2326 0 0 746
    2022  4 2052 0 0 747
    2022  5 2059 0 0 748
    2022  6 1656 0 0 749
    2022  7 1574 0 0 750
    2022  8 1386 0 0 751
    2022  9 1361 0 0 752
    2022 10 1071 0 0 753
    2022 11 1154 0 0 754
    2022 12 1109 0 0 755
    2023  1 1076 0 0 756
    2023  2 1264 0 0 757
    2023  3 1174 0 0 758
    2023  4  906 0 0 759
    2023  5  968 0 0 760
    2023  6 1012 1 0 761
    2023  7 1097 1 0 762
    2023  8 1517 1 0 763
    2023  9 1249 1 0 764
    2023 10 1098 1 0 765
    2023 11  975 1 0 766
    2023 12 1000 1 0 767
    2024  1 1112 1 1 768
    2024  2 1060 1 1 769
    2024  3  945 1 1 770
    2024  4 1017 1 1 771
    2024  5  916 1 1 772
    2024  6 1120 1 1 773
    Attached Files

  • #2
    #1 #2 #3 are standard problems for options described under

    Code:
    help axis label options
    For #4

    Code:
    search shading
    reveals several resources such as

    Code:
    Blog    . . . . . . . . . . . . Adding recession shading to time-series graphs
            . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D. Schenck
            2/20    http://blog.stata.com/2020/02/13/adding-recession-shading-
                    to-time-series-graphs/
    
    SJ-16-3 gr0067  . Speaking Stata: Shading zones on time series and other plots
            . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
            Q3/16   SJ 16(3):805--812                                (no commands)
            discusses background shading of time series and other plots

    Comment

    Working...
    X