简体   繁体   English

在 R 中保存来自 function 的多个图

[英]Save multiple plots from function in R

I am using the R package intensity.analysis and the function CIA of the package.我正在使用 R package 强度分析和 function CIA 的 ZEFE70A8E604A7C6D。 Once I execute the function, I get multiple plots.执行 function 后,我会得到多个图。 However, one is overlapping on the other and I can only see and save the last one.但是,一个重叠在另一个上,我只能看到并保存最后一个。

Probably it is a simple question, but I have not found any answer googling it, as many people refer to displaying several plots at the same time.可能这是一个简单的问题,但我在谷歌上没有找到任何答案,因为很多人指的是同时显示多个图。 What I want is being able to see all the graphs that the function generates automatically and save them.我想要的是能够看到 function 自动生成的所有图表并保存它们。

Could you provide me any help?你能给我任何帮助吗? I will leave you the code below.我会给你下面的代码。

Edit: actually I have the same question that this user posted before ( How can I save multiple sequential plots generated by one function in R? ).编辑:实际上我有这个用户之前发布的相同问题( 如何在 R 中保存由一个 function 生成的多个连续图? )。 However, I have not the code of the function, so I cannot even try to play with it and avoid the parameter that the answer to that question gives as the solution.但是,我没有 function 的代码,所以我什至无法尝试使用它并避免使用该问题的答案给出的参数作为解决方案。

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)

you can set your graphical parameters with the par() function您可以使用 par() function 设置图形参数

par(mfrow= c(2,2))

the mfrow argument takes a vector of dim 2 to create a "raster" of plot's mfrow 参数采用昏暗 2 的向量来创建绘图的“栅格”

so所以

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

will give you this:会给你这个:

like this:像这样:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM