benjann / reldist

Stata module for relative distribution analysis
MIT License
5 stars 1 forks source link

control of the olabel and the yolabel #2

Closed ericmelse closed 1 year ago

ericmelse commented 1 year ago

Dear Ben, the reldist cdf plot control of the calibration of the olabel and the yolabel is rather sophisticated. As such it provides an evenly positioning of the tick marks without and with lables, like with my ects example code:

reldist cdf pl_ptnaherk , by(b18cohort) cat // atx(ref) // atx(comp) // k(epan2)
reldist gr , olabel(, labsize(*.9)) otitle(ects, m(t-3 b+1)) ///
    yolabel(, labsize(*.9) angle(0)) yotitle(ects, m(l+0 r-3)) ///
    refline(lc(navy)) lc(maroon) ciopts(color(maroon%30) lw(0) lp(none) pstyle(p1)) ///
    aspect(1) xsize(10) ysize(10) ylabel(0(.1)1,angle(0)) xlabel(0(.1)1) ///
    xsca(noex ax(1)) xsca(noex ax(2)) ysca(noex ax(1)) ysca(noex ax(2)) ///
    yoline(50, lc(gs10) lp(dash)) yoline(40, lc(gs10) lp(shortdash)) /// 
    ytit("Cohort 2018 (cum. prob.)" , m(l-2 r+1)) ///
    xtit("Cohort 2017 (cum. prob.)" , m(t+2 b-2))

which results in: HVA_FBE_18vs17_ects_reldist_cdf_olabel_standard But, this requires some manipulation because I have a specific purpose for the ticks as to give attention to the scores 40 and 50 ects. So, I tried this code:

reldist gr , olabel(0 5 10 20 30 40 50 58 60, labsize(*.9)) otitle(ects, m(t-3 b+1)) ///
    yolabel(0 5 10 20 30 40 50 58 60 , labsize(*.9) angle(0)) yotitle(ects, m(l+0 r-3)) ///
    refline(lc(navy)) lc(maroon) ciopts(color(maroon%30) lw(0) lp(none) pstyle(p1)) ///
    aspect(1) xsize(10) ysize(10) ylabel(0(.1)1,angle(0)) xlabel(0(.1)1) ///
    xsca(noex ax(1)) xsca(noex ax(2)) ysca(noex ax(1)) ysca(noex ax(2)) ///
    yoline(50, lc(gs10) lp(dash)) yoline(40, lc(gs10) lp(shortdash)) /// 
    ytit("Cohort 2018 (cum. prob.)" , m(l-2 r+1)) ///
    xtit("Cohort 2017 (cum. prob.)" , m(t+2 b-2))

which results in: HVA_FBE_18vs17_ects_reldist_cdf_olabel_set_1 This is somewhat besides what I want, because reldist decides which ticks get a label or not, so I tried this:

reldist gr , olabel(0 5 10 20 40 50 58 60, labsize(*.9)) otitle(ects, m(t-3 b+1)) ///
    yolabel(0 5 10 20 40 50 58 60 , labsize(*.9) angle(0)) yotitle(ects, m(l+0 r-3)) ///
    refline(lc(navy)) lc(maroon) ciopts(color(maroon%30) lw(0) lp(none) pstyle(p1)) ///
    aspect(1) xsize(10) ysize(10) ylabel(0(.1)1,angle(0)) xlabel(0(.1)1) ///
    xsca(noex ax(1)) xsca(noex ax(2)) ysca(noex ax(1)) ysca(noex ax(2)) ///
    yoline(50, lc(gs10) lp(dash)) yoline(40, lc(gs10) lp(shortdash)) /// 
    ytit("Cohort 2018 (cum. prob.)" , m(l-2 r+1)) ///
    xtit("Cohort 2017 (cum. prob.)" , m(t+2 b-2))

which results in: HVA_FBE_18vs17_ects_reldist_cdf_olabel_set_2 Again, I am a little frustrated because, for example, why would the two axis not get 20 on that tick (plenty room for it), so I tried this code with the manual control of labels (or not) for each tick, using regular Stata syntax:

reldist gr , olabel(0 "0" 5 " " 10 "10" 20 " " 40 "40" 50 "50" 58 "58" 60 "60", labsize(*.9)) otitle(ects, m(t-3 b+1)) ///
    yolabel(0 "0" 5 " " 10 "10" 20 "20" 40 "40" 50 "50" 58 "58" 60 "60" , labsize(*.9) angle(0)) yotitle(ects, m(l+0 r-3)) ///
    refline(lc(navy)) lc(maroon) ciopts(color(maroon%30) lw(0) lp(none) pstyle(p1)) ///
    aspect(1) xsize(10) ysize(10) ylabel(0(.1)1,angle(0)) xlabel(0(.1)1) ///
    xsca(noex ax(1)) xsca(noex ax(2)) ysca(noex ax(1)) ysca(noex ax(2)) ///
    yoline(50, lc(gs10) lp(dash)) yoline(40, lc(gs10) lp(shortdash)) /// 
    ytit("Cohort 2018 (cum. prob.)" , m(l-2 r+1)) ///
    xtit("Cohort 2017 (cum. prob.)" , m(t+2 b-2))

which results in: HVA_FBE_18vs17_ects_reldist_cdf_olabel_set_3 Note that reldist gr is not giving me any complaints about using regular Stata syntax to set the ticks and their labels in this manner, but, at reldist gr is not processing as I expect. Like with this (rather silly) example:

tw line pl_ptnaherk pl_ptnaherk if flag==1, aspect(1) xsize(10) ysize(10) ///
xlabel(0 "0" 5 "5" 10 "10" 20 "" 30 "30" 40 "40" 50 "50" 56 "56" 58 " " 60 "60", labsize(*.9)) ///
ylabel(0 "0" 5 "5" 10 "10" 20 "" 30 "30" 40 "40" 50 "50" 56 "56" 58 " " 60 "60", labsize(*.9) angle(none)) ///
yline(50, lc(gs10) lp(dash)) yline(40, lc(gs10) lp(shortdash)) ysca(noex) /// 
xline(50, lc(gs10) lp(dash)) xline(40, lc(gs10) lp(shortdash)) xsca(noex)

which results in: HVA_FBE_18vs17_ects_tw_line_label_set

So, my request is if it could be possible to control the position manually by the regular coding of tick marks and their labels (or not using " ") for olabel and yolabel?

benjann commented 1 year ago

I think what you want is the noprune subpotion, that is, type olabel(0 5 10 20 40 50 58 60, noorune). You can also specify prune(#) to set the pruning tolerance. The default is prune(0.1); for example, try prune(0.05).

Furthermore, also xlabel() and ylabel() should work, but you have to select the relevant axis, e.g., xlabel(..., axis(2)).

ben

benjann commented 1 year ago

Qualification: apart from selecting the axis, an issue with direct use of xlabel() and ylabel() of course is that the positions on the axis corresponding to specific outcome values are not known; this is why there is the olabel() option.

ericmelse commented 1 year ago

Dear Ben, many thanks for pointing me in the right direction, prune(0) or noprune does the job just fine (I do apologize for my poor help file reading, all of this is well documented): HVA_FBE_18vs17_ects_reldist_cdf_olabel_pruned