Announcement

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

  • Bold headings in forestplot appear as {bf:Heading}

    Hi everyone,

    Similar to a previous question, I am trying to edit the formatting of headings created via David Fisher's admetan and forestplot. I would like all headings of my forestplot to be bold, but currently only one out of five headings displays properly. The problem I experience is visualized below:

    Click image for larger version

Name:	Grapherror.png
Views:	1
Size:	20.0 KB
ID:	1531233


    The code I used to produce this graph follows the linked question almost verbatim:

    Code:
    admetan lnseor lnselci lnseuci, study(cohort) by(antibody) nooverall rcol(senneg senpos) nohet effect("OR")  saving(graphdata)
    use graphdata, clear
    
    * Make headings bold
    replace _LABELS = `"{bf:"' + _LABELS + `"}"' if _USE==0
    label var senneg `"{bf: n SE/N neg}"'
    label var senpos `"{bf: n SE/N pos}"'
    label var _EFFECT `"{bf: OR (95% CI)}"'
    label var _WT `"{bf: % Weight}"'
    label var _LABELS `"{bf:Shared Epitope}"'
    
    * Replace "Subgroup" text with "Total"
    replace _LABELS = `"{bf: Total}"' if _USE==3
    
    forestplot, useopts nostats nowt rcols(_EFFECT _WT senneg senpos)
    For some reason _EFFECT responds appropriately to de {bf:} SMCL formatting, but the other headings do not. Besides centering, I cannot discern any obvious differences between these five variables that explain this. When I restart Stata and try again from scratch, sometimes _LABELS (ie: Shared Epitope) is appropriately bolded, sometimes it isn't, which make me feel like it is a bug.

    I am using admetan/forestplot version 3.2 in Stata SE 14.1.

    Any help would be appreciated!
    Best,
    Emma


  • #2
    Dear Emma,

    Thankyou for your message. This is indeed a recognised problem, and not one with a simple answer I'm afraid.

    The issue is that forestplot automatically chops up the label string, and displays it on multiple lines, if the string is wider (i.e. longer) than its corresponding data format. For instance, the string "% Weight" is 8 characters long, whereas the data is typically only 6 characters long (e.g. "100.00"). However, SMCL tags such as "{bf: ... }" appear to be part of the label string, and are chopped up accordingly. This separates the opening tag {bf: from the closing tag }, and therefore twoway cannot apply the tag when the plot is finally drawn.

    I can suggest two ways of dealing with this, though neither are entirely satisfactory:

    1) Force the entire label string to be displayed on a single line, regardless of its width. To do this, pass the option
    maxlines(1) to forestplot (e.g. on the final line of your code).

    2) Exploit the fact that labels can already be split using Stata's built in twoway command. For instance, you can use options such as title("First line" "Second line"). So, assuming we already know if and where our label string should be split, we can "do it ourselves".

    For instance...
    Code:
    label var _WT `"{bf:% Weight}"'


    ... might be changed to:
    Code:
    label var _WT `""{bf:%}" "{bf:Weight}""'


    Depending on the length of the string, and whether it contains multiple words (per line), you may also need to add the maxlines(#) and/or maxwidth(#) options.


    I hope this is helpful!

    Best wishes,

    David.

    Comment


    • #3
      Dear David,

      Thank you very much for your clear reply! It didn't occur to me that the breaking across lines could be disrupting the SMCL tags, I'm glad to know it. Your second suggestion perfectly addresses my needs.

      Thank you again!
      Best wishes,
      Emma

      Comment

      Working...
      X