Announcement

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

  • Multiple rows in x-axis (months and years in t-axis)

    I'm currently working with some data that I need visualized over time since March 2020. I'm using labels for each month, but I'd like a second row of labels for year (under the "Jan" label). I've tried different ways, including using compound double quotes, which gets me halfway, but removed all the formatting I have on my text. I was wondering if there is any solution to this, or if I can simply superimpose a second x-axis (or rather t-axis).

    If someone would know how to also add a different major tick type with the years that would also be excellent, preferably with a stronger line than what I have.

    Here is a code example:

    Code:
    twoway (tsline test2, lcolor(black) lwidth(medthick) ) ///
        if(date >= 21975 & date <= 22646), /// 
        xtitle("", size (small)) ///
        ytitle("", size(small)) ///
        graphregion(margin(l+0 r+5 b+1 t+0 )) ///
        graphregion(color(white)) plotregion(color(white)) /// 
        title(" ") legend(label(1 "Test") label(2 "") label(3 "") label(4 "") label(5 "") label(6 "")  size(small) position(12) region(style(none)) row(2) ) ///
        note("I'd like to have useful labels on my tscale", size (vsmall)) ///
        yscale(range(1.05)) ytick() ymtick() ylab(1 "0%" 0.8 "-20%" 0.6 "-40%", angle(0) labsize(8pt) grid glcolor(gs15) glwidth(medthick)) ///
        tscale(range(21975 22464)) ttick() tmtick() tline() tlab(21975 "Mar" 22006 "Apr" 22036 "May" 22067 "Jun" 22097 "Jul" 22128 "Aug" 22159 "Sep" 22189 "Oct" 22220 "Nov" 22250 "Dec" 22281 `" "Jan" "2021" "' 22312 "Feb" 22340 "Mar" 22371 "Apr" 22401 "May" 22432 "Jun" 22464 "Jul" 22493 "Aug" 22523 "Sep" 22554 "Oct" 22585 "Nov" 22616 "Dec" 22646 `" "Jan" "2022" "', angle(45) labsize(8pt) grid glcolor(gs15) glwidth(medthick))
    I realize that much of the code is superfluous to my question, but I think it might be illustrative.

    The code above results in the following, which is unsatisfactory:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	81.5 KB
ID:	1640547


    I don't know if I need to give any example data, but I gave it a shot here :


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(date test2)
    21975 1.0330738
    21976 1.0400368
    21977  1.041943
    21978 1.0437903
    21979  1.047563
    21980         .
    21981         .
    21982 1.0434924
    21983 1.0361438
    21984  1.023855
    21985 1.0058279
    21986  .9747817
    21987  .9539434
    21988   .948198
    21989  .9342902
    21990  .9226986
    21991  .9090697
    21992  .8922921
    21993  .8776307
    21994  .8595895
    21995  .8510076
    21996  .8451368
    21997  .8458519
    21998  .8423389
    21999  .8490808
    22000         .
    22001  .8589349
    22002   .863746
    22003  .8683782
    22004  .8776492
    end
    format %td date

  • #2
    I managed to solve it quite neatly with the following:


    Code:
    tscale(range(21975 22464)) ttick() tmtick() tline() tmlab(21975 "mar" 22006 "apr" 22036 "maj" 22067 "jun" 22097 "jul" 22128 "aug" 22159 "sep" 22189 "okt" 22220 "nov" 22250 "dec" 22281 "jan " 22312 "feb" 22340 "mar" 22371 "apr" 22401 "maj" 22432 "jun" 22464 "jul" 22493 "aug" 22523 "sep" 22554 "okt" 22585 "nov" 22616 "dec" 22646 "jan " , angle(45) labsize(9pt) grid glcolor(gs15) glwidth(medthick)) tlab(22281 `" " " "  " "2021" "' 22646 `" " " " " "2022" "', labsize(2.9pt) grid glcolor(gs14) glwidth(medthick))
    Click image for larger version

Name:	Graph2.png
Views:	1
Size:	73.3 KB
ID:	1640722

    Last edited by Carl Fredrik; 13 Dec 2021, 09:39.

    Comment

    Working...
    X