I'm looking for a way to print a list of histograms to a PDF in R.
I've found a bunch of ways to do it for ggplot2 plots, but none for histograms. I am using the base histogram functions.
I'm looking for a way to print a list of histograms to a PDF in R.
I've found a bunch of ways to do it for ggplot2 plots, but none for histograms. I am using the base histogram functions.
For base graphics, use par(mfrow=c(2,2)) for example. If you print more than 4 plots, it will flow over into a new page, if you are using the pdf graphics output.
OK, just in case ggplot could be an alternative:
library(tidyverse)
df <- data.frame(
b = rnorm(10000)
, c = 1:10000
)
df %>%
ggplot(aes(b)) +
geom_histogram()
The R Graphics Cookbook helps. ;)