Announcement

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

  • Meta - Forest plot - How do we get high-res figures in large meta-analyses?

    Dear statalisters,

    -meta- with the option forestplot is capable of producing great forest plots, which cannot be paralleled by any other Stata package I am aware of.

    However, -meta- fails to generate high-resolution graphs when meta-analyses are large (i.e., many studies; > 70 estimates). When I save the graph as a tiff figure (or copy and paste it into LibreOffice/ Microsoft Office), the resolution is not good enough for publication. Here is an example:


    Code:
    clear
    set obs 85
    gene es = rnormal(0,0.05)
    gene se = runiform(0.05,0.1)
    metan es se,  textsize(320)
    
    meta set es se
    meta forestplot
    Do you have any tip to increase the size of the graph, or augment its resolution? Are you aware of any new or updated command that could do the trick?

    All the best,

    Tiago

  • #2
    Tiago, there is a solution to your problem that I will outline below, but let me also make some remarks on the specific type of graph as you have outlined. A forest plot with 70+ studies is a lot to fit as one uninterrupted graphic for any reasonable page. The example you have presented could be made 12 inches tall but may only be a few inches wide, and all text and figures may remain an uncomfortably small print size. I have seen these very long forest plots split horizontally so that they fall over two pages, which is nicer to read and display, but I have wondered if that's the publication staff cutting up the image, or if they request the underlying data from the author to remake the figure themselves. All this to say, you may want to consider how the information will be displayed in a pdf for reviewers as much as on the page for readers.

    Now let's look at specifics. First, I strongly recommend learning to work with vector graphics (SVG in particular). Vector graphics are parametric representations of images so they may be scaled to be any arbitrarily large size and resolution without losing quality. However, SVGs are not universally viewable and often need special viewers to properly import/export (e.g., photo manipulation programs), although on Windows the Edge browser does a decent job of displaying them. For the more common formats, JPG and PNG work well for embedding in documents but both do not scale once made. I cannot recommend using Stata to make TIFF files because StataCorp have not implemented the LZW-compressed version of TIFF images, so instead high-resolution images result in huge (uncompressed) TIFF files, unsuitable for embedding into documents or uploading to most author platforms. (You can of course manually compress the TIF files, but then again, with the added step you may as well work from SVG as a starting point.)

    Lets export the forest plot.

    Code:
    meta forestplot, name(gg, replace)
    graph save gg, replace
    graph export gg.svg, as(svg) replace
    graph export gg.jpg, as(jpg) height(12000) quality(100) replace
    *graph export gg.tif, as(tif) height(12000) replace // do at your own risk, this will be 140 MB
    Stata accepts width and height in pixels, up to a maximum of 16,000 in each dimension. How you work out resolution is in terms of dots per inch, though you don't explicitly set that information, say with the non-existent -dpi()- option. With 16,000 px, this may be represented as 16 inches at 1000 dpi (often suitable for hi-res line art) or 166.67 inches at 96 dpi (the typical resolution for web browsing).

    I will open the JPG file in Irfanview just to show the image properties, in particular the dimensions and implicit dpi.

    Click image for larger version

Name:	info1.PNG
Views:	1
Size:	36.4 KB
ID:	1674735

    When Stata made the file, it used our specified dimension of 12,000 px in height, and the implied width is 3837 px. It also set a resolution flag of 96x96 dpi. However, this is just a guideline for printing/displaying, all the pixel information is the same at 96 dpi or 1200 dpi. Even though the pixels are there, some image formats also want to know what the DPI is. JPG is like this as was shown, and Stata sets a default 96 dpi for height and width. PNG files, being created without a specified dpi, will mean that other programs try to infer the resolution and may default to 72x72 dpi or something else. It's just a guess for how to scale the image display.

    Note: what happens when images are embedded in Word or LibreOffice is a whole different game because (at least with default settings), it may also apply its own image rescaling such as to fit on the page, or resampling and recompression so as to optimize for fast viewing.

    It would be nice if Stata could augment graph export's functionality to include an explicit dpi() option that would prevent a lot of confusion with the same kind of question.

    Comment


    • #3
      Dear Leonardo,


      Many thanks for your time and crystal clear explanations! What a magnificent solution. Very very clever. Thank you so much! Really helpful. I have adapted your suggestions to our code, and it worked like a charm!


      All the best,

      Tiago

      Comment


      • #4
        You’re welcome. I’m happy that it worked well for you.

        Comment

        Working...
        X