freeazabird
freeazabird

Reputation: 401

How to combine 4 graphs into one image

I have four mini graphs that I would like to combine into one image. Is this possible to achieve in base R?

 #graphs1
 par(mar=c(0, 5, 0, 2.1))
 H <- c(0, 0, 2, 0, 21) # Create the data for the chart, cont3.#
 M <- c("Very Low", "Low", "Medium", "High", "Very High")

  barplot(H, col =c("slategray1", "slategray1","slategray1",
                             "slategray1", "steelblue3"), 
  horiz = TRUE, 
  family="Arial", border = NA, names.arg = M, 
  xlim = range(0,100), ylim = range(0, 0.08), 
  axes = FALSE, width = 0.01, las=1, xaxt='n') 

  #graph2
  par(mar=c(0, 5, 0, 2.1))

  H <- c(0, 0, 1, 4, 18) # Create the data for the chart
  M <- c("Very Low", "Low", "Medium", "High", "Very High")

  barplot(H, col =c("slategray1", "slategray1","slategray1",
              "slategray1", "steelblue3"), 
    horiz = TRUE, 
    family="Arial", border = NA, names.arg = M, 
    xlim = range(0,100), ylim = range(0, 0.08), 
    axes = FALSE, width = 0.01, las=1, xaxt='n') 

  #graphs3
  par(mar=c(0, 5, 0, 2.1))

  H <- c(0, 1, 3, 4, 14) # Create the data for the chart 
  M <- c("Very Low", "Low", "Medium", "High", "Very High")

  barplot(H, col =c("slategray1", "slategray1","slategray1",
              "slategray1", "steelblue3"), 
    horiz = TRUE, 
    family="Arial", border = NA, names.arg = M, 
    xlim = range(0,100), ylim = range(0, 0.08), 
    axes = FALSE, width = 0.01, las=1, xaxt='n') 

 #graph4
 par(mar=c(0, 5, 0, 2.1))
 H <- c(0, 1, 4, 4, 16) # Create the data for the chart, cont3.#
 M <- c("Very Low", "Low", "Medium", "High", "Very High")

 barplot(H, col =c("slategray1", "slategray1","slategray1",
              "slategray1", "steelblue3"), 
    horiz = TRUE, 
    family="Arial", border = NA, names.arg = M, 
    xlim = range(0,100), ylim = range(0, 0.08), 
    axes = FALSE, width = 0.01, las=1, xaxt='n') 

I would like the four graphs created in the code above to be combined into one image in base R.

Upvotes: 0

Views: 1162

Answers (1)

Dij
Dij

Reputation: 1378

Before you create the first plot, run:

par(mfrow = c(2,2))

to place the four plots on a 2 x 2 grid, that can be exported as one image.

Upvotes: 2

Related Questions