How to keep forest plot from getting cut off?

Viewed 220

I am creating several forest plots, but they are all getting cut off knit the RMD. Reproducible example:

author = c("aaaaaaaaaa", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "t", "u", "v", "w", "x")
Ne = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)
Me = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)
SDe = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)
Nc = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)
Mc = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)
SDc = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)

df = data.frame(author, Ne, Me, SDe, Nc, Mc, SDc)

m.cont <- meta::metacont(n.e = Ne,
                   mean.e = Me,
                   sd.e = SDe,
                   n.c = Nc,
                   mean.c = Mc,
                   sd.c = SDc,
                   studlab = author,
                   data = df,
                   sm = "SMD",
                   method.smd = "Hedges",
                   fixed = FALSE,
                   random = TRUE,
                   method.tau = "REML",
                   hakn = TRUE,
                   title = "Example")

meta::forest.meta(m.cont, 
            sortvar = TE,
            predict = TRUE, 
            print.tau2 = FALSE,
            leftlabs = c("Author", "g", "SE"),
            xlim = "symmetric")

I know I can get the full figures through running block without knitting and then expanding the figure, but I'd like these plots to be presentable within the knit html doc.

1 Answers

Simply specify the width and height of your figure in the chunk header.

---
title: "Testing"
output: html_document
---

```{r,fig.width = 10,fig.height=10}
#above this is where you can add dimensions
author = c("aaaaaaaaaa", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "t", "u", "v", "w", "x")
Ne = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)
Me = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)
SDe = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)
Nc = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)
Mc = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)
SDc = c(1, 2, 3, 4, 5, 6, 7, 8, 8, 34, 5, 6, 7, 8, 4, 3, 2, 7, 3, 6, 7, 8, 5)

df = data.frame(author, Ne, Me, SDe, Nc, Mc, SDc)

m.cont <- meta::metacont(n.e = Ne,
                         mean.e = Me,
                         sd.e = SDe,
                         n.c = Nc,
                         mean.c = Mc,
                         sd.c = SDc,
                         studlab = author,
                         data = df,
                         sm = "SMD",
                         method.smd = "Hedges",
                         fixed = FALSE,
                         random = TRUE,
                         method.tau = "REML",
                         hakn = TRUE,
                         title = "Example")

meta::forest.meta(m.cont, 
                  sortvar = TE,
                  predict = TRUE, 
                  print.tau2 = FALSE,
                  leftlabs = c("Author", "g", "SE"),
                  xlim = "symmetric",)

```

When you knit it you should then get: output

Related