从列表中绘制 tif 文件会导致错误:'x'是一个列表,但没有组件“x”;和'y'
我安装了以下库:
library(rgdal)
library(raster)
require(sf)
library(ggplot2)
library(raster)
library(rgeos)
library(tidyverse)
library(leaflet)
library(sp)
library(bnspatial)
用于绘图的 tif 文件是通过导入的
#import tif-files
rlist=list.files(getwd(), pattern="tif$", full.names=FALSE)
for(i in rlist) { assign(unlist(strsplit(i, "[.]"))[1], raster(i)) }
> print(rlist)
[1] "nightlight_3150.tif" "nightlight_450.tif" "population_1000.tif"
[4] "population_3000.tif" "road_class_1_5000.tif" "road_class_2_100.tif"
[7] "road_class_2_25.tif" "road_class_2_50.tif" "road_class_3_300.tif"
[10] "road_class_3_3000.tif" "trop_mean_filt.tif"
我试图通过列表 tifs
绘制其中几个 tif 文件:
tifs = list(nightlight_3150, nightlight_450 、population_1000、population_3000)。
tif 文件列表将用于 for 循环。当我打印列表的第一项 tifs
时,我得到以下输出:
> print(tifs[1])
[[1]]
class : RasterLayer
dimensions : 2000, 2000, 4e+06 (nrow, ncol, ncell)
resolution : 3e-04, 3e-04 (x, y)
extent : 4.5817, 5.1817, 52.0697, 52.6697 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : nightlight_3150.tif
names : nightlight_3150
values : 0, 97.12836 (min, max)
当我尝试绘制列表中的第一项时,我收到错误:
> plot(tifs[1])
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
我尝试应用另一篇文章的建议解决方案( 'x' 是一个列表,但是没有组件“x”和“y”)到我的代码。但是,这样做也会导致错误:
> plot(tifs[1]$(4.5817, 5.1817), tifs[1]$(52.0697, 52.6697))
Error: unexpected '(' in "plot(tifs[1]$("
从列表中绘制每个 tif 文件的正确方法是什么?
谢谢
I have the following libraries installed:
library(rgdal)
library(raster)
require(sf)
library(ggplot2)
library(raster)
library(rgeos)
library(tidyverse)
library(leaflet)
library(sp)
library(bnspatial)
The tif files that are used for plotting are imported via
#import tif-files
rlist=list.files(getwd(), pattern="tifquot;, full.names=FALSE)
for(i in rlist) { assign(unlist(strsplit(i, "[.]"))[1], raster(i)) }
> print(rlist)
[1] "nightlight_3150.tif" "nightlight_450.tif" "population_1000.tif"
[4] "population_3000.tif" "road_class_1_5000.tif" "road_class_2_100.tif"
[7] "road_class_2_25.tif" "road_class_2_50.tif" "road_class_3_300.tif"
[10] "road_class_3_3000.tif" "trop_mean_filt.tif"
I am trying to plot several of those tif files via a list tifs
:
tifs = list(nightlight_3150, nightlight_450, population_1000, population_3000).
The list of tif files will be used for a for loop. When I print the first item of the list tifs
I get the following output:
> print(tifs[1])
[[1]]
class : RasterLayer
dimensions : 2000, 2000, 4e+06 (nrow, ncol, ncell)
resolution : 3e-04, 3e-04 (x, y)
extent : 4.5817, 5.1817, 52.0697, 52.6697 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : nightlight_3150.tif
names : nightlight_3150
values : 0, 97.12836 (min, max)
When I try to plot the first item in the list I get the error:
> plot(tifs[1])
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
I tried to apply the proposed solution of another post ('x' is a list, but does not have components 'x' and 'y') to my code. However, doing so also results in an error:
> plot(tifs[1]$(4.5817, 5.1817), tifs[1]$(52.0697, 52.6697))
Error: unexpected '(' in "plot(tifs[1]$("
What is the correct way of plotting each tif file from a list?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论