0

I created a forest plot using metafor. The data I downloaded all has two significant figures after the decimal point for the study means and SDs, but when it uploads to the forest plot, these trailing zeros are dropped.

How can I keep these trailing zeros to make it look better?

The code for the forest plot is:

forest(meta2, showweights = TRUE, ilab.xpos=c(-24.5,-22, -19.5, -16, -13.75, -11),
       ilab=cbind(bmi_awm$Intervention_n, bmi_awm$Intervention_mean, bmi_awm$Intervention_SD, bmi_awm$Comparison_n, bmi_awm$Comparison_mean, bmi_awm$Comparison_SD),(digits=2),
       ilab.pos = 4,
       rows=c(48), ylim=c(-1, 51.5), xlim=c(-35.5, 14), at=(c(-7, 0, 7))

enter image description here

markalex
  • 8,623
  • 2
  • 7
  • 32

1 Answers1

0

See the documentation of the forest() function:

https://wviechtb.github.io/metafor/reference/forest.rma.html

digits: integer to specify the number of decimal places to which the tick mark labels of the x-axis and the annotations should be rounded (the default is 2L). Can also be a vector of two integers, the first to specify the number of decimal places for the annotations, the second for the x-axis labels. When specifying an integer (e.g., 2L), trailing zeros after the decimal mark are dropped for the x-axis labels. When specifying a numeric value (e.g., 2), trailing zeros are retained.

The problem in your code is that you have digits=2 wrapped in parentheses. Get rid of those and the training zeros should be retained.

Wolfgang
  • 2,810
  • 2
  • 15
  • 29
  • Thanks for getting back to me, Wolfgang. No luck- when I remove the parentheses, the trailing zeros still disappear. par(mar=c(4,4,1,2)) forest (meta2) forest(meta2, showweights = TRUE, ilab.xpos=c(-24.5,-22, -19.5, -16, -13.75, -11), ilab=cbind(bmi_awm$Intervention_n, bmi_awm$Intervention_mean, bmi_awm$Intervention_SD, bmi_awm$Comparison_n, bmi_awm$Comparison_mean, bmi_awm$Comparison_SD),digits=2, ilab.pos = 4, rows=c(48)... – Mary Rozga Nov 18 '21 at 13:44
  • Any other ideas? I can get "digits" to work for the output, but not in displaying the Mean, SD on the left of the forest plot (data from the studies). – Mary Rozga Nov 18 '21 at 13:46
  • Are you talking about the extra annotations that you are adding with `ilab`? Those are not touched by `digits`. If you want to do any formating of those, you need to do this yourself. For example, if you want to display a number always with 2 decimals places, you could use `formatC()`. For example: `formatC(5, format="f", digits=2)`. – Wolfgang Nov 18 '21 at 20:52