Announcement

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

  • Meta forestplot: problems with axis range/labels

    I am having trouble setting axis range and labels using meta forestplot. I am using Stata 16.1.

    I am trying to display the results of a forest plot of vaccine efficacy trials, with 2 group binary variables, that are combined using log RR.
    After using the forestplot transform function (transform(efficacy)) to exponentiate the log relative risk and subtract from 1 to show vaccine efficacy, I cannot suitably modify the axis range or title.

    Here is my example code:

    Code:
    input id HepB3_HBsAg HepB3_HBsAg_neg unvac_HBsAg unvac_HBsAg_neg
    id HepB3_HBsAg HepB3_HBsAg_neg unvac_HBsAg unvac_HBsAg_neg
    1. 2 253 59    416
    2. 2 90    19 29
    end
    meta esize HepB3_HBsAg HepB3_HBsAg_neg unvac_HBsAg unvac_HBsAg_neg, esize(lnrratio) studylabel(id) random(sjonkman)
    Here is the default output:
    Code:
    meta forestplot, transform(Vaccine efficacy: efficacy)
    Which produces a forestplot with unusual x axis labels at 0.63 to 0.98., as below. I'd like to set this to 0 to 1.0, with 0.2 interval labels.
    Click image for larger version

Name:	Graph1.png
Views:	1
Size:	43.7 KB
ID:	1583290



    This is what happens if I try to change the axis range using xcale or xlabel using either of these commands:
    Code:
    meta forestplot, transform(Vaccine efficacy: efficacy) xscale(range(0 1))
    meta forestplot, transform(Vaccine efficacy: efficacy) xlabel(0 0.5 1)
    Click image for larger version

Name:	Graph2.png
Views:	1
Size:	41.4 KB
ID:	1583291



    If I use untransformed values for the scale range, I can change the range so it is more suitable, but I am unable to change the axis labels:
    Code:
    meta forestplot, transform(Vaccine efficacy: efficacy) xscale(range(-4.6 -2.3))
    Click image for larger version

Name:	Graph3.png
Views:	1
Size:	43.1 KB
ID:	1583292



    Code:
    meta forestplot, transform(Vaccine efficacy: efficacy) xscale(range(-4.6 -2.3)) xlabel(0 0.5 1)
    Click image for larger version

Name:	Graph4.png
Views:	1
Size:	40.6 KB
ID:	1583293


    It also doesn't work if I use untransformed figures for the xlabels (eg. xlabel(-4.6, -2.3))
    Assistance on how to achieve a scale from 0 to 1.0 with suitable x axis labels would be much appreciated.

    Alex

  • #2
    Is there a method to plot this meta forestplot output on a linear scale even though the underlying data are based on log-transformed values?

    Comment


    • #3
      Hi Alex,

      You should specify x-axis labels on the output metric, which is the efficacy metric if you specified option transform(efficacy). The range of your data is .74 to .99 so it is preferable to choose values between these 2 numbers. For example,
      Code:
       meta forest, transform(Vaccine efficacy: efficacy) esrefline xlabel(.75 .95 .99)
      Click image for larger version

Name:	Graph1.png
Views:	1
Size:	106.0 KB
ID:	1584087


      Notice how the value labels seem equidistant even though .95-.75 = .2 is far larger than .99 - .95 = .04. This because these labels are plotted on the efficacy metric and the corresponding values on the original log(RR) metric are in fact equidistant (they are roughly -1.4, -3, and -4.6; take log(1-efficacy) for each value). If you would like to plot the data on the [0,1] range, you could do something like:
      Code:
      meta forest, transform(Vaccine efficacy: efficacy) esrefline xlabel(0 .999, format(%9.0f))
      Click image for larger version

Name:	Graph2.png
Views:	1
Size:	103.7 KB
ID:	1584088


      For now, you should avoid specifying the value 1 in options range() or xlabel() when the efficacy transformation is chosen. This is because when efficacy = 1, the RR is 0 which is computationally not possible since a continuity correction of 0.5 is usually added by default to the zero cells to avoid this scenario. Finally, you mentioned that you would like to have labels between 0 and 1 with 0.2 intervals. This choice would not look nice for this example since you are plotting these values on the efficacy metric (and the range of your values are .74 to .99). You may play with the following code to add more value labels between 0 and 1
      Code:
      meta forest, transform(Vaccine efficacy: efficacy) esrefline xlabel(0 0.80 0.98 .999, format(%9.2f))
      I hope this helps!

      Comment


      • #4
        I am unfortunately having a similar issue and I suspect it is, like the OP's issue, related to attempting to graph effect estimates on a logarithmic scale.

        As an example, I am attempting to reproduce a forest plot in a Cochrane meta-analysis on HPV vaccine-related outcomes. This is the forest plot from the Cochrane analysis:

        Click image for larger version

Name:	Screenshot 2026-04-14 225727.png
Views:	2
Size:	139.7 KB
ID:	1785723



        My code to reproduce these values is as follows:

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str32 study float(log_eff log_cilb log_ciub)
        "Skufca 2018-FIN"   .3364722 -.6867298  1.359673
        "Thomsen 2020-DNK" -.6161861 -1.659185 .42681295
        end
        Code:
        meta set log_eff log_cilb log_ciub, civarlevel(95) random(dlaird) studylabel(study) civartolerance(0.5)
        Code:
        meta forestplot, transform(exp) crop(0 100) ciopts(barbsize(1) lcolor(black)) markeropts(mcolor(red) msize(medlarge)) omarkeropts(mcolor(black)) nullrefline columnopts(_esci, supertitle("Effect estimate")) title("Forest plot example") xlab(0.01 0.1 1 100) nonotes

        When I use the following code to reproduce the "short-term" results, I wind up with this:
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	157.0 KB
ID:	1785724


        You can see that it has mostly reproduced the forestplot elements, but the x-axis is getting partially covered up by the study and heterogeneity estimate text. Also the tenths and hundredths decimal places are visible after the values for 1 and 100, which I do not want.

        I am not really sure what else I can do to convince Stata to not put text over the forest plot (even if the effect estimates in the plot don't go all the way to 0.01). I've tried asking it to label it between 0 and 0.999, which gets a little closer but doesn't afford me the ticks that are visible in the Cochrane example. Does anyone have advice?
        Attached Files

        Comment


        • #5
          Originally posted by Maria Sundaram View Post
          Does anyone have advice?
          Thanks for the reproducible example. I think that you have to explicitly specify the range of the x-axis so that the axis does not extend to the text (see highlighted).

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input str32 study float(log_eff log_cilb log_ciub)
          "Skufca 2018-FIN"   .3364722 -.6867298  1.359673
          "Thomsen 2020-DNK" -.6161861 -1.659185 .42681295
          end
          
          meta set log_eff log_cilb log_ciub, civarlevel(95) random(dlaird) studylabel(study) civartolerance(0.5)
          
          meta forestplot, transform(exp) crop(0 100) ciopts(barbsize(1) lcolor(black)) ///
          markeropts(mcolor(red) msize(medlarge)) omarkeropts(mcolor(black)) nullrefline ///
          columnopts(_esci, supertitle("Effect estimate")) title("Forest plot example") ///
          xlab(0.01 0.1 1 100) xsc(r(0.01 100)) nonotes
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	40.2 KB
ID:	1785733

          Comment


          • #6
            This worked perfectly, Andrew! Thank you so much.

            I'm afraid I have a follow-up question: You will notice that the font kerning on the effect estimates and 95% CIs (in the column to the right of the plot) seems off. Specifically, it seems like there is an extra space after the opening bracket for the 95% CIs.

            Do you know, by chance, whether this is something that can be fixed?

            Thank you again so much for all your help!

            Comment


            • #7
              You could force a negative margin to eliminate the extra space.


              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input str32 study float(log_eff log_cilb log_ciub)
              "Skufca 2018-FIN"   .3364722 -.6867298  1.359673
              "Thomsen 2020-DNK" -.6161861 -1.659185 .42681295
              end
              
              meta set log_eff log_cilb log_ciub, civarlevel(95) random(dlaird) studylabel(study) civartolerance(0.5)
              meta forestplot, transform(exp) crop(0 100) ciopts(barbsize(1) lcolor(black)) ///
              markeropts(mcolor(red) msize(medlarge)) omarkeropts(mcolor(black)) ///
              nullrefline columnopts(_esci, supertitle("Effect estimate")) ///
              columnopts(_esci, plotregion(margin(-2))) title("Forest plot example") ///
              xlab(0.01 0.1 1 100) xsc(r(0.01 100)) nonotes
              Click image for larger version

Name:	Graph.png
Views:	1
Size:	40.6 KB
ID:	1785738

              Comment


              • #8
                Amazing. Thank you so much!!

                Comment


                • #9
                  Of course, if that seems too compressed, experiment with lower values, e.g, -0.5, -0.75, -1 and -1.25.

                  Comment

                  Working...
                  X