How to increase size of output from multiple plots in R

65 Views Asked by At

I am trying to adjust the height and width of the output comprised of the plots of the posterior draws of multiple variables, using the mcmc_combo() function (trace and density plots), as the size does not scale with the number of variables:

Code sample:

library(cmdstanr)
library(bayesplot)
library(dplyr)

draws <- fit2$draws(
    variables = param[-5],
    inc_warmup = TRUE,
    format = "df"
)
pars <- grep("lam", names(draws), value = TRUE)

mcmc_combo(draws, pars = pars)

Output: image|500x500 As the image shows, the graphs get too truncated to display the y-axis altogether.

I then tried plotting the variables one-by-one, using lapply():

lapply(pars, function(x) {mcmc_combo(draws, pars = x)})

image|500x500

image|500x500 As you can see, the plot window remains the same size, and the graph(s) are stretched to fit the window.

It would be better if I could fix the size of each individual graph, and have the plot window adapt to this instead. How can I accomplish this?

1

There are 1 best solutions below

0
jay.sf On

Using a different device such as png or pdf as described elsewhere. The trick is to adjust height= parameter. You can also play around with graphical parameters such as ?mar (as long as your method it doesn't use grids).

set.seed(42)

png('foo.png', width=400, height=1200)
par(mfrow=c(9, 2))
lapply(seq_len(18), \(i) hist(rnorm(100), "FD", col=4)) |> invisible()
dev.off()

enter image description here

Consider RStudio plot visualization as a preview window.