R 中一页上的多个图 [英] Multiple Plots on 1 page in R

查看:42
本文介绍了R 中一页上的多个图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 R 的一个 pdf 页面上绘制 7 个不同的图形?

How can I plot 7 different graphs on one pdf page on R?

我目前使用的是 matplot,它似乎没有这个选项.我需要根据数据列绘制数据列.

I currently use matplot, which doesn't seem to have this option. I need to plot columns of data against columns of data.

我最初尝试使用格子库来执行此操作,但我似乎无法弄清楚如何绘制数据列.好像想要一个函数.

I initially tried to do this with the lattice library, but I can't seem to figure out how to plot the columns of data. It seems to want a function.

推荐答案

要创建绘图的 pdf,您可以执行以下操作.要初始化 pdf 文档,首先使用带有文件名的 pdf 函数.dev.off() 最后会关闭图形设备并完成pdf.之后,您应该会在工作目录中看到一个新文档(在本例中为plots.pdf").

To create a pdf of plots, you can do something like this. To initialize a pdf document use the pdf function with a file name first. dev.off() at the end will close the graphics device and complete the pdf. Afterwards, you should see a new document in the working directory (in this example - 'plots.pdf').

d <- data.frame(matrix(sample(c(1:700), 2000, TRUE), 10, 20))
pdf('plots')
par(mfrow = c(3, 3))  ## set the layout to be 3 by 3
sapply(1:9, function(i) plot(d[,i]))
dev.off()

生成此 pdf

这篇关于R 中一页上的多个图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆