Announcement

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

  • graph twoway: two x-axis, lines and line labelling

    Hi folks - apologies a bit of a beginner with the plotting in Stata, but was wondering if anyone knew a good solution to this. I can't quite seem to get it to do what I want... many thanks in advance!

    Basically - I want to display percentile xlines for the exposure (intensity distribution over a day), but I want these percentile lines to be labelled correctly from the top and leave the exposure on the bottom x-axis. I can achieve this somewhat by switching from xaxis(1 2) to xaxis(1 2) - but the latter then doesn't seem to then align the labels and lines/markers properly? Wondered if anyone had any suggestions on this.

    Code below and output as examples for context.

    OPTION 1 - passable but would rather the percentile labels on top axis and exposure on bottom
    Code:
    graph twoway rarea lowerM0 upperM0 $exposure, color(gs2%30) ///
    || line hrM0 hrM1 hrM2 hrM2_CC hrM2_PD $exposure, lpattern(solid) lcolor(black) lwidth(medthick) ///
    legend(order(2 "M0 (95%CI)" 3 "M1" 4 "M2" 5 "M2_CC" 6 "M2_PD") ///
    ring(0) bmargin(small) position(7) bmargin(large) size(small) symxsize(6.5) keygap(1.0) col(1))
    ytitle("HR relative to $ref_cat") xlabel(-3.3 (0.3) -1.2) ///
    yscale(log) yline(1, lpattern(solid) lcolor(black%90)) scheme(plottig) ///
    xaxis(1 2) xline($p10 $p90 , lstyle(foreground) lcolor(gs12)) ///
    xline($p25 $p50 $p75, lstyle(foreground) lcolor(gs5)) ///
    xlabel($p10 "p10" $p50 "p50" $p90 "p90", axis(2) labsize(small)) xtitle("", axis(2)) ///
    subtitle("$exposure; ALL_MODELS", size(small) ring(0) pos(11))
    OPTION 2 - axis labels right top and bottom - but percentile labels are out of line with lines for some reason?
    Code:
    graph twoway rarea lowerM0 upperM0 $exposure, color(gs2%30) ///
    || line hrM0 hrM1 hrM2 hrM2_CC hrM2_PD $exposure, lpattern(solid) lcolor(black) lwidth(medthick) ///
    legend(order(2 "M0 (95%CI)" 3 "M1" 4 "M2" 5 "M2_CC" 6 "M2_PD") ///
    ring(0) bmargin(small) position(7) bmargin(large) size(small) symxsize(6.5) keygap(1.0) col(1))
    ytitle("HR relative to $ref_cat") xlabel(-3.3 (0.3) -1.2) ///
    yscale(log) yline(1, lpattern(solid) lcolor(black%90)) scheme(plottig) ///
    xaxis(2) xline($p10 $p90 , lstyle(foreground) lcolor(gs12)) ///
    xline($p25 $p50 $p75, lstyle(foreground) lcolor(gs5)) ///
    xlabel($p10 "p10" $p50 "p50" $p90 "p90", axis(2) labsize(small)) xtitle("", axis(2)) ///
    subtitle("$exposure; ALL_MODELS", size(small) ring(0) pos(11))

    OPTION 1
    Click image for larger version

Name:	Option 1.JPG
Views:	1
Size:	131.1 KB
ID:	1581219






    OPTION 2
    Click image for larger version

Name:	Option 2.JPG
Views:	1
Size:	128.3 KB
ID:	1581220

    Last edited by patrick handcock; 11 Nov 2020, 03:31.
Working...
X