简体   繁体   English

使用“ filled.contour”绘制地图

[英]Plotting maps using 'filled.contour'

I am plotting a map in R using 'filled.contour()' and I do not understand why this function switches the x,y axis. 我正在使用'filled.contour()'在R中绘制地图,但我不明白为什么该函数会切换x,y轴。 I have: 我有:

x=1:20
y=1:10
z=array(seq(1,2000,1),dim=c(length(y),length(x)) )
filled.contour(x,y,z,plot.title=title(main="Test",xlab="X",ylab="Y")  )

Error in .filled.contour(x, y, z, levels, col) : dimension mismatch .filled.contour(x,y,z,level,col)中的错误:尺寸不匹配

but if I enter: 但是如果我输入:

z=array(seq(1,2000,1),dim=c(length(x),length(y)) )

it plots the map correctly. 它可以正确绘制地图。 All documentation about arrays shows that 'dim' is defined as dim(y,x) Am I missing something? 有关数组的所有文档都显示'dim'被定义为dim(y,x)我是否缺少某些内容?

The issue is what you are passing through the contour function. 问题是您正在通过轮廓函数传递什么。 You have to pass x and y in the order that you set z as the dimensions of. 您必须按照将z设置为尺寸的顺序传递x和y。 So the reason that z=array(seq(1,2000,1),dim=c(length(x),length(y))) worked is because you called for 所以z=array(seq(1,2000,1),dim=c(length(x),length(y)))起作用的原因是因为您要求

filled.contour(**x**,**y**,z,plot.title=title(main="Test",xlab="X",ylab="Y"))

The code below runs as you would hope. 下面的代码按您希望的那样运行。

x=1:20
y=1:10
z=array(seq(1,2000,1),dim=c(length(y),length(x)))
filled.contour(y,x,z,plot.title=title(main="Test",xlab="X",ylab="Y")  )

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

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