0

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.

longlivebrew
  • 301
  • 3
  • 16
  • When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. How exactly do you want this plots be be arranged? How many do you have? – MrFlick Jan 22 '18 at 20:47
  • Also, are you aware that ggplot2 and histograms don't contradict each other? ggplot can take a plethora of form, for example histograms. – Georgery Jan 22 '18 at 21:07
  • @Georgery - I was not aware, thanks for the info. The few samples applicable to ggplot2 did not work in my case. – longlivebrew Jan 22 '18 at 21:19

2 Answers2

0

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.

thc
  • 9,527
  • 1
  • 24
  • 39
0

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. ;)

Georgery
  • 7,643
  • 1
  • 19
  • 52