绘制两个彼此相邻的森林图

时间:2020-05-17 14:16:35

标签: r gridextra forestplot

我已经使用以下代码设法制作了两个单独的图:

第一个情节:

<h2>
  Choose an Option:
</h2>
<select id="test">
  <option value="option_1">Option 1</option>
  <option value="option_2">Option 2</option>
  <option value="option_3">Option 3</option>
</select>

<h3>
  Add Ons:
</h3>
<div class="wc-pao-addon-tone-cap">
  <div class="wc-pao-addon-description">
    <p>
      These are the add ons that you can have:
    </p>
  </div>
  <p>
    <label><input type="checkbox">Add On 1</label>
  </p>
  <p>
    <label><input type="checkbox">Add On 2</label>
  </p>
  <p>
    <label><input type="checkbox">Add On 3</label>
  </p>
</div>

第二个图:

Male_data <- 
  structure(list(
    mean = c(NA, 1.0, 1.8, 2.2, 1.7),
    lower = c(NA,1.0, 1.7, 1.8, 1.5),
    upper = c(NA, 1.0, 2.0, 2.6, 1.8)),
    .Names = c("mean", "lower", "upper"),
    row.names = c(NA, -5L),
    class = "data.frame")

tabletext2 <- cbind(
  c("Sub-group tested", "Variable 1", "Variable 2", "Variable 3", "Variable 4"),
  c("HR[95%CI]", "1.0[1.0 - 1.0]", "1.8[1.7 -2.0]", "2.2[1.8 - 2.6]", "1.7[1.5 - 1.8]"), 
  c("No. of participants", "209,750", "14,027", "1,468", "12,559"), 
  c("Competing risk HR", "1.0", "2.0", "2.6", "1.9"))

forestplot(tabletext2, Male_data, hrzl_lines = list("2" = gpar(lty = 2)), new_page = TRUE, is.summary = FALSE, vertices = TRUE, xlab = "Hazard ratio", graph.pos = 4, graphwidth = unit(5, "cm"), boxsize = 0.10, xlog = TRUE,
           txt_gp=fpTxtGp(xlab = gpar(cex = 0.5, fontface = "bold", just = "center"), label = gpar(columns = 3, just = "center")))

然后我尝试使用forestplot和GridExtra包中的以下内容,以同一图的面板彼此并排的方式进行绘制:

Female_data <- 
  structure(list(
    mean = c(NA, 1.0, 2.2, 4.1, 1.9),
    lower = c(NA,1.0, 1.9, 3.1, 1.6),
    upper = c(NA, 1.0, 2.5, 5.5, 3.1)),
    .Names = c("mean", "lower", "upper"),
    row.names = c(NA, -5L),
    class = "data.frame")

tabletext3 <- cbind(
  c("Sub-group tested", "Variable 1", "Variable 2", "Variable 3", "Variable 4"),
  c("HR[95%CI]", "1.0[1.0 - 1.0]", "2.2[1.9 -2.5]", "4.1[3.1 - 5.5]", "1.9[1.6 - 3.1]"), 
  c("No. of participants", "260,760", "8,260", "1,096", "7,164"), 
  c("Competing risk HR", "1.0", "3.2", "4.9", "2.8"))

forestplot(tabletext3, Female_data, hrzl_lines = list("2" = gpar(lty = 2)), new_page = TRUE, is.summary = FALSE, vertices = TRUE, xlab = "Hazard ratio", graph.pos = 4, graphwidth = unit(5, "cm"), boxsize = 0.10, xlog = TRUE,
           txt_gp=fpTxtGp(xlab = gpar(cex = 0.5, fontface = "bold", just = "center"), label = gpar(columns = 3, just = "center")))

其余代码运行正常,但是当涉及到popViewport()时,出现以下错误:

grid.Call.graphics(C_unsetviewport,as.integer(n))中的错误:无法弹出顶级视口(“ grid”和“ graphics”输出混合?) 2。 grid.Call.graphics(C_unsetviewport,as.integer(n)) 1。 popViewport()

我该如何克服?

0 个答案:

没有答案