当数据不在规则网格上时如何绘制等高线图? [英] How to draw a contour plot when data are not on a regular grid?

查看:19
本文介绍了当数据不在规则网格上时如何绘制等高线图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有 3 个变量,使得

Say I have 3 variables such that

x=1:9
y=c(1,1,1,2,2,2,3,3,3)
z=6:14

如何重新排列数据以便我可以使用 r 绘制数据的等高线图?我收到消息

How can I rearrange the data so that I can make a contour plot of the data with r? I am getting the message

Error in contour.default(x, y, z) : 
  increasing 'x' and 'y' values expected

谢谢.

推荐答案

z 是要绘制等高线的值的 matrix.xy 是它们各自的位置."Tyler" 在 r-help 邮件列表解释了这一点,并举例说明了如何转换数据以使其正常工作.另请参阅 ?contour 帮助中的示例.

z is a matrix of values where contour lines are to be drawn. x and y are their respective location. "Tyler" at r-help mailing list explains this and gives an example of how to transform your data to make things work. See also examples in the help of ?contour.

x = seq(0, 10, by = 0.5)
y = seq(0, 10, by = 0.5)
z <- outer(x, y)

contour(x, y, z)

这篇关于当数据不在规则网格上时如何绘制等高线图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆