【问题标题】:Save multiple plots from function in R从R中的函数保存多个图
【发布时间】:2020-07-09 16:33:54
【问题描述】:

我正在使用 R 包强度分析和包的功能 CIA。执行该函数后,我会得到多个图。但是,一个重叠在另一个上,我只能看到并保存最后一个。

可能这是一个简单的问题,但我在谷歌上没有找到任何答案,因为很多人指的是同时显示多个图。我想要的是能够看到函数自动生成的所有图表并保存它们。

你能帮我什么忙吗? 我会把下面的代码留给你。

编辑:实际上我有这个用户之前发布的相同问题 (How can I save multiple sequential plots generated by one function in R?)。但是,我没有函数的代码,所以我什至无法尝试使用它并避免使用该问题的答案给出的参数作为解决方案。

library(sf)
library(sp)
library(raster)
library(rgdal)
library(sabre)
library(intensity.analysis)

C05 <- raster("C05.rst")
C11 <- raster("C11.rst")
C18 <- raster("C18.rst")

raster.layers <- list(C05, C11, C18)
time.points <- c("2005","2011","2018")
categories <- c("Agricultural areas", "Vegetation areas", "Urban fabric", "Industrial and commercial areas", "Mineral extraction sites", "Dump sites", "Road and rail networks", "Port areas", "Airports", "Artificial green urban areas", "Open spaces with little or no vegetation", "Water bodies", "Background")

crosstab.output <- crosstabulation <- multicrosstab(raster.layers, time.points, categories)

CIA.output <- CIA(crosstabulation, time.points, categories)
filename <- file.path(normalizePath(tempdir(), winslash = "/"), "CIA.csv")
CIA2csv(CIA.output, time.points, categories, filename)

【问题讨论】:

    标签: r plot raster


    【解决方案1】:

    您可以使用 par() 函数设置图形参数

    par(mfrow= c(2,2))
    
    

    mfrow 参数采用暗淡 2 的向量来创建绘图的“光栅”

    所以

    plot(x)
    plot(x)
    plot(x)
    plot(x)
    
    

    会给你这个:

    像这样:

    【讨论】:

    • 非常感谢您的帮助! :) 但是,它不起作用。一旦我执行了这个函数,它至少会给我一个序列中的 5 个不同的图,我是否执行你先告诉我的函数并不重要,因为它每个只给我一个
    猜你喜欢
    • 2021-12-23
    • 2021-05-06
    • 2012-12-24
    • 1970-01-01
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    相关资源
    最近更新 更多