gpt4 book ai didi

R 轮廓和填充轮廓不能放在一起

转载 作者:行者123 更新时间:2023-12-02 00:10:44 25 4
gpt4 key购买 nike

我想画一张全局海面温度的图片,但是在我填充海面轮廓之后,我尝试在填充的图片上添加更宽的计数器,然后一些奇怪的事情发生了,这些拖曳图片无法拼合在一起这是代码,因为我没有空间放原始数据,所以使用了一个随机数

这是代码

library(maps)

ee<-array(rnorm(89*180),dim=c(89,180))

lati <- seq(-90,90,length=89) #Latitudes goes from -90 to 90 as far as I know :)
long <- seq(-180,180,length=180)
plot(NA, xlim=c(-180,180), ylim=c(-90,90), xlab="", ylab="", xaxs="i", yaxs="i")
contour(long, lati, t(ee), add=TRUE)
filled.contour(long,lati,t(ee), color.palette=terrain.colors)
maps::map(database="world", fill=TRUE, col="light blue", add=TRUE)

我们看到,填充图片的位置与原始数据不对应比如唯一的轮廓图

问题是什么?

最后抱歉我的英语不好,谢谢大家

最佳答案

您可以在 filled.contour 帮助页面中阅读以下内容:

The output produced by ‘filled.contour’ is actually a combination of two plots; one is the filled contour and one is the legend. Two separate coordinate systems are set up for these two plots, but they are only used internally - once the function has returned these coordinate systems are lost. If you want to annotate the main contour plot, for example to add points, you can specify graphics commands in the ‘plot.axes’ argument. See the examples.

因此,尝试将此应用于您的示例,您可以执行以下操作:

library(maps)
ee<-array(rnorm(89*180),dim=c(89,180))
lati <- seq(-90,90,length=89) #Latitudes goes from -90 to 90 as far as I know :)
long <- seq(-180,180,length=180)
draw.map <- function() {maps::map(database="world", fill=TRUE, col="light blue", add=TRUE)}
filled.contour(long,lati,t(ee), color.palette=terrain.colors, plot.axes=draw.map())

给出:

enter image description here

关于R 轮廓和填充轮廓不能放在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15571303/

25 4 0