How to draw a contour plot when data are not on a regular grid?

百般思念 提交于 2019-11-27 22:43:55

问题


Say I have 3 variables such that

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

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

Thank you.


回答1:


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)


来源:https://stackoverflow.com/questions/5847042/how-to-draw-a-contour-plot-when-data-are-not-on-a-regular-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!