Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R中的ggplot2在多个文件中创建多个绘图_R_Plot_Ggplot2 - Fatal编程技术网

使用R中的ggplot2在多个文件中创建多个绘图

使用R中的ggplot2在多个文件中创建多个绘图,r,plot,ggplot2,R,Plot,Ggplot2,使用ggplot2在R中创建多个文件时遇到异常问题 我要为多个人创建多个绘图,所以我要在pdf中为每个人创建所有绘图。所以事情是这样的 for(i in 1:10) { pdf(paste("person",i,".pdf",sep="")) ggplot2(...)+......... ggplot2(...)+......... ggplot2(...)+......... ggplot2(...)+......... dev.off() }

使用ggplot2在R中创建多个文件时遇到异常问题

我要为多个人创建多个绘图,所以我要在pdf中为每个人创建所有绘图。所以事情是这样的

for(i in 1:10)
{
    pdf(paste("person",i,".pdf",sep=""))
    ggplot2(...)+.........
    ggplot2(...)+.........
    ggplot2(...)+.........
    ggplot2(...)+.........
    dev.off()
}
我已经验证了创建绘图的所有代码都正常工作,并且创建一个pdf文件正常工作,没有问题。当我尝试运行循环时,问题出现了,它创建了文件,但它们是空的。我已经尝试了我能想到的一切,但似乎找不到任何有关这方面的信息。我在RStudio(Windows)和命令行(ubuntu)中尝试过,两者都会产生相同的问题


任何见解或替代方案都将不胜感激,谢谢您需要为每个要输出为pdf的绘图使用
打印

library(ggplot2)
dat = data.frame(x1=rnorm(10), x2=rnorm(10))
for(i in 1:2){
    pdf(paste("person",i,".pdf",sep=""))
    p1 = ggplot(dat, aes(x=x1)) + geom_histogram()
    p2 = ggplot(dat, aes(x=x2)) + geom_histogram()
    print(p1)
    print(p2)
    dev.off()
    }