【问题标题】:R png() Function Adding Extra Stuff to Filenames and Ignoring Image Size FlagsR png() 函数向文件名添加额外的东西并忽略图像大小标志
【发布时间】:2021-06-01 17:28:52
【问题描述】:

我有一个正在运行的 R 脚本,它几乎完成了,但还有一个最后一个问题。我在 R 中使用 png(filename = " ", width = N, height = M, units =" ", ...) 函数,但它将宽度、高度和单位标志附加到 png 文件名。我在默认帮助中找不到解决此问题的方法。

我使用的确切命令是

 for(i in 1:length(lst)){
 
 png(paste0(filename = paste( lst[i]), ".png", width = 1280, height = 688, units = "px"))
 
 ...all plotting code...

 dev.off()

 }

其中lst[i] 是通过循环读取的文件名列表。我最终会调用 .png 文件

idq27qecq.png1280688px 其中 1280688px 是我在名称中不想要的东西。 png 文件也全部尺寸不正确,尺寸为 480 x 480 像素。

我该如何解决这个问题?

如果我在开头删除 paste0,我会收到错误

png 错误(文件名 = 粘贴(lst[i]),“.png”,宽度 = 1280,高度 = 688,: 'pointsize' 参数无效

还有

在 png(filename = paste(lst[i]), ".png", width = 1280, height = 688, 中: 强制引入的 NAs

修复我的输出图像的名称和大小的任何帮助都会有所帮助。 我看了这个帖子 save multiple plots r into separate jpg 但即使我尝试实现它也没有用。

所有这些都是通过脚本在 Rstudio 引擎中完成的。

【问题讨论】:

    标签: r save png


    【解决方案1】:

    第一个paste0 不需要,第二个paste 也应该只用于创建filename 值。试试看:

    for(i in 1:length(lst)){
      png(filename = paste(lst[i], ".png"), width = 1280, height = 688, units = "px")
      #  
      #...all plotting code...
      #
      dev.off()
    }
    

    【讨论】:

    • 感谢这项工作,我对 R 比较陌生,这很有帮助
    猜你喜欢
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-05
    • 1970-01-01
    • 1970-01-01
    • 2010-11-27
    相关资源
    最近更新 更多