2

我经常在 RStudio 中创建大图,将其保存为 PDF,但也希望部分显示在 PDF knitr 报告中。有没有办法创建完整的对象,然后剪切一块(最好是左上角)并将第二张图片包含在 PDF 报告中?

例如,一个 pheatmap 代码生成一个包含 56 列和 100 行的图。我只想显示最左上角的 10col 和 10 行,但是如果我对输入数据进行采样,由于对不同数据进行聚类,我显然会得到另一个图。此外,我希望有一个适用于任何绘图类型(不仅是 pheatmap)的解决方案。

drows <- "euclidean"
dcols <- "euclidean"
clustmet <- "complete"

col.pal <- c("lightgrey","blue")

main.title <- paste("Variant (freq>", minfreq, "%) in all samples", sep="") 

hm.parameters.maj <- list(hm.maj.data, 
                      color = col.pal,
                      fontsize = 10,
                      cellwidth = 14, 
                      cellheight = 14, 
                      scale = "none",
                      treeheight_row = 200,
                      kmeans_k = NA,
                      show_rownames = T, 
                      show_colnames = T,
                      main = main.title,
                      clustering_method = clustmet,
                      cluster_rows = TRUE, 
                      cluster_cols = FALSE,
                      clustering_distance_rows = drows, 
                      clustering_distance_cols = dcols,
                      legend=FALSE)

# To draw the heatmap on screen (comment-out if you run the script from terminal)
do.call("pheatmap", hm.parameters.maj)

# To draw to file (you may want to adapt the info(header(vcf))sizes)
outfile <- paste("major-variants_heatmap_(freq>", minfreq, ")_", drows, ".pdf", sep="")
do.call("pheatmap", c(hm.parameters.maj, filename=outfile, width=24, height=35))

在此先感谢斯蒂芬

4

0 回答 0