R用轮廓着色地图

时间:2013-03-22 06:53:14

标签: r map contour

我想用R绘制sst(海面温度),但是仍然有一些错误,作为一个新的,请告诉我问题出在哪里

rr.txt像这样格式化

  89 rows  180 cols means 2*2 grid data

ee<-read.table("C:\\Users\\topmad\\Desktop\\New folder\\rr.txt")
ee
dim(ee)
long<-seq(0,360,2)
lati<-seq(0,180,2)
m<-c(91:180, 1:90)
m
length(m)

require(maps)
maps::map(database="world", fill=TRUE, col="light blue")
maps::map.axes()
contour(long,lati,ee[,m], add=TRUE)
par(ask=TRUE)

1 个答案:

答案 0 :(得分:3)

您的问题与您的尺寸有关。

#Let's create some random values:
ee<-array(rnorm(89*180),dim=c(89,180))

#If ee has 89 rows (corresponding to latitude I guess) then lati needs 89 values:
lati <- seq(-90,90,length=89) #Latitudes goes from -90 to 90 as far as I know :)
#Same thing with columns/longitude:
long <- seq(-180,180,length=180)

#you probably want your contour behind the continents so first an empty plot:
plot(NA, xlim=c(-180,180), ylim=c(-90,90), xlab="", ylab="", xaxs="i", yaxs="i")
#Then your contour (you need to transpose ee so that rows are longitudes):
contour(long, lati, t(ee), add=TRUE)
# And then your continents:
maps::map(database="world", fill=TRUE, col="light blue", add=TRUE)

enter image description here