如何将4张图合并为一张图像

时间:2019-07-10 00:41:14

标签: r

我想将四个迷你图合并为一张图像。是否可以在基数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') 

我希望将以上代码中创建的四个图形组合到基数R中的一个图像中。

1 个答案:

答案 0 :(得分:2)

在创建第一个图之前,运行:

par(mfrow = c(2,2))

将四个图放置在2 x 2的网格上,可以将其导出为一张图像。