我试图在世界 Map 上绘制不同颜色的年度太阳辐射数据 . 我正在使用R编程 .
我使用的数据来自http://eosweb.larc.nasa.gov/sse/global/text/global_radiation
首先,我将此数据转换为空间数据帧以及使用map(world)函数获取到空间形式的世界 Map .
我正在效法https://www.r-bloggers.com/maps-of-solar-radiation/
用于绘制我的代码如下 . 我相信代码完全正确,但我收到了一些错误
library(sp)
library(maps)
library(mapdata)
library(maptools)
library(RColorBrewer)
nasafile <- 'http://eosweb.larc.nasa.gov/sse/global/text/global_radiation'
nasa <- read.table(file=nasafile, skip=13, header=TRUE)
proj <- CRS('+proj=latlon +ellps=WGS84')
coords = nasa[,2:1]
datos = nasa[,3:15]
nasaSP <- SpatialPixelsDataFrame(points=coords, data=datos, proj4string=proj)
world <- map("world", plot=FALSE)
llCRS <- CRS("+proj=latlong +ellps=WGS84")
world_sp <- map2SpatialLines(world, proj4string=llCRS)
colar_sp = colorRampPalette(c("snow1", "thistle1", "plum2", "red4"))
map_sp <- list('sp.lines', world_sp)
spplot(nasaSP["Ann"], col.regions=color_sp, sp.layout=map_sp)
我得到的主要错误与预测有关 . 我相信我在代码中添加它们的方式是正确的,并且已经看到了许多以相同方式编写它们的示例 . 请查看这些错误,并了解如何使此代码正常工作 .
提前致谢!
错误:
Error in CRS("+proj=latlon +ellps=WGS84") :
northings must follow eastings: +proj=latlon +ellps=WGS84
Error in checkSlotAssignment(object, name, value) :
assignment of an object of class “function” is not valid for slot ‘proj4string’ in an object of class “Spatial”; is(value, "CRS") is not TRUE
Error in CRS("+proj=latlong +ellps=WGS84") :
northings must follow eastings: +proj=latlong +ellps=WGS84
Error in initialize(value, ...) : object 'llCRS' not found
1 回答
我发现你的代码存在两个问题:
1)你错误地使用
CRS
. 在CRS("+proj=latlong...)
而不是latlong
中,您必须使用longlat
(参见?CRS
);2)绘制 Map 时,
color_sp
被称为colar_sp
.这是您的代码,其中包含更正: