本文介绍了在R中使用多个面板准备出版质量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个特殊的问题,即以tiff格式生成300ppi的图表以供发布。我发现ggsave可以在一个单一的情节中工作得很漂亮,然后可以将它导出到GIMP来压缩生成的大型tiff文件。然而,当绘制两个数字相邻时,它似乎遇到了麻烦,例如 plot1 plot2< -ggplot(.........) grid.arrange(plot1,plot2,ncol = 2) ggsave(filename =Figure 1.tiff,scale = 1,width = 10,height = 5, units =cm,dpi = 300) pre> 这导致只有plot2出现在生成的tiff文件中,而图1无处可见。 我也会有一个不使用ggplot的图,但是它包含三个使用barplot2和matplot生成的图,但是这可能会遇到类似的问题。本质上,任何人都可以提出一种方法,将剧情窗口中出现的情节(我使用RStudio)中出现的内容翻译成高分辨率的tiff文件,并尽可能地小题大做? 'plotP'< - function(P){#P是一个图表列表需要(gridExtra) N Ncol Nrow grid .newpage() pushViewport(viewport(layout = grid.layout(Nrow,Ncol))) row< - 1 col< - 1 for(i in 1:N){ print(P [[i]],vp = viewport(layout.pos.row = row,layout.pos.col = col)) col< - col + 1 if(col> Ncol){ col< - 1 row< - row + 1 } } } 现在您可以在一个命令中绘制数字并保存设备 plotP(list(plot1,plot2)) name< - 'plot of grid' height< - 6 宽度< -8 dpi< -300 dev.copy(tiff,paste0(name,.tiff),width = width * dpi,height = height * dpi)尝试(dev.off(),silent = TRUE)#close window 希望它有帮助, p> 亲切的问候 I have quite a specific problem with producing 300ppi plots in tiff format for publication. I have found ggsave to work beautifully with a single plot, which can then be exported to GIMP to compress the resulting large tiff file. However, it seems to run into trouble when plotting two figures next to each other, e.g.plot1<-ggplot(.........)plot2<-ggplot(.........)grid.arrange(plot1, plot2, ncol=2)ggsave(filename = "Figure 1.tiff", scale = 1, width = 10, height = 5, units = "cm", dpi = 300)This results in only plot2 appearing in the resulting tiff file, with plot 1 nowhere to be seen. I will also have a figure which does not use ggplot, but consists of three plots produced with barplot2 and matplot, but presumably this faces a similar problem. Essentially, could anyone suggest a way of translating what appears in the plot appearing in the plot window (I use RStudio) to a high-resolution tiff file with as little fuss as possible? 解决方案 I recently had the same issue and I could not find a ready made solution, I ended up creating a wrapping function for a list of ggplot objects that tries to plot the entries on a kind of balanced grid. 'plotP' <- function (P){ # P is a list of plots require(gridExtra) N <- length(P) Ncol <- ceiling(sqrt(N)) Nrow <- ceiling(N/Ncol) grid.newpage() pushViewport(viewport(layout=grid.layout(Nrow, Ncol))) row <- 1 col <- 1 for (i in 1:N){ print(P[[i]], vp=viewport(layout.pos.row=row, layout.pos.col=col)) col <- col + 1 if (col > Ncol){ col <- 1 row <- row + 1 } }}Now you can plot the figures in one command and save the deviceplotP(list(plot1, plot2))name <- 'grid-of-plots'height <- 6width <- 8dpi <- 300dev.copy(tiff, paste0(name, ".tiff"), width = width*dpi, height =height*dpi)try(dev.off(), silent = TRUE)#close windowhope it helps,kind greetings 这篇关于在R中使用多个面板准备出版质量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 13:31