Announcement

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

  • metan forestplot text alignment

    Hi there

    I've been using metan command to create forest plots but I'm having trouble with text alignment of the columns.

    Example below (the content of the "Count" column comes out misaligned on the forest plot). Do others experience the same problem? I'm using Stata 17/MP

    With many thanks



    * Example generated by -dataex-. For more info, type help dataex

    Code:
    clear
    input str5 Subgroup str5 Count float(OR l_95ci u_95ci) str19 OR_95CI str33 Group
    "This"     "20" 1.2 1.1 1.3 "1.2 (1.1 to 2.2)" "Grp1"
    "That"    "200" 1.2 1.1 1.3 "1.2 (1.1 to 2.2)" "Grp1"
    "Other"     "1" 1.2 1.1 1.3 "1.2 (1.1 to 2.2)" "Grp1"
    "This"    "4" 1.2 1.1 1.3 "1.2 (1.1 to 2.2)" "Grp2"
    "That"   "2134" 1.2 1.1 1.3 "1.2 (1.1 to 2.2)" "Grp2"
    "Other" "12309" 1.2 1.1 1.3 "1.2 (1.1 to 2.2)" "Grp2"
    "This"    "123" 1.2 1.1 1.3 "1.2 (1.1 to 2.2)" "Grp3"
    "That"   "1234" 1.2 1.1 1.3 "1.2 (1.1 to 2.2)" "Grp3"
    "Other"   "123" 1.2 1.1 1.3 "1.2 (1.1 to 2.2)" "Grp3"
    end
    
    foreach var of varlist * {
    label variable `var' `""{bf:`var'}" ""
    }
    
    metan OR l_95ci u_95ci, lcols(Subgroup Count) rcols(OR_95CI) effect(mean) nowt nosubgroup by(Group) forestplot(nobox range(0.6 1.4) xlabel(0.8(.2)1.4) null(1) nlineop(lwidth(thin) lpattern(dash) lc(maroon)) texts(75)) ysize(4.5) nostats nooverall
    Last edited by tim bradshaw; 29 Nov 2022, 10:36.

  • #2
    Hi Tim,
    Apologies for the late response. I am a co-author and maintainer of the metan package.

    The issue you raise is a valid one, and it stems from the way Stata constructs graphs using twoway. Specifically: to display right-justified text, we need to calculate the display width of each line, and then ask Stata to place each line at the appropriate x-coordinate such that the right-hand ends line up. Unfortunately, for various reasons it is not always easy to work out the correct x-coordinate -- I have tried various things in the past -- although that's not to say there's no solution! (Notice that left-justified text will always line up perfectly!)

    Best wishes,
    David.

    Comment


    • #3
      Many thanks, David.

      I followed your suggestion of justifying left, as below, but that leaves a large empty space on the right of the graph. Any suggestions on how to remove this would be much appreciated.

      Code:
      metan OR l_95ci u_95ci, lcols(Subgroup Count) rcols(OR_95CI) effect(mean) nowt nosubgroup by(Group) forestplot(leftjustify astext(70) nobox range(0.8 1.4) ///
      xlabel(0.8(.2)1.4) null(1) nlineop(lwidth(thin) lpattern(dash) lc(maroon))) nostats nooverall
      Last edited by tim bradshaw; 16 Jan 2023, 09:35.

      Comment

      Working...
      X