如何计算R中轮廓内的面积?
我想知道是否可以在 R 中计算轮廓内
的面积。例如,由以下结果产生的轮廓面积:
sw<-loess(m~l+d)
mypredict<-predict(sw, fitdata) # Where fitdata is a data.frame of an x and y matrix
contour(x=seq(from=-2, to=2, length=30), y=seq(from=0, to=5, length=30), z=mypredict)
抱歉,我知道这段代码可能很复杂。如果太难读的话。任何可以向我展示如何计算简单生成的轮廓面积的示例都会有所帮助。
感谢您的任何帮助。
I'm wondering if it is possible to caclulate the area within a contour in R.
For example, the area of the contour that results from:
sw<-loess(m~l+d)
mypredict<-predict(sw, fitdata) # Where fitdata is a data.frame of an x and y matrix
contour(x=seq(from=-2, to=2, length=30), y=seq(from=0, to=5, length=30), z=mypredict)
Sorry, I know this code might be convoluted. If it's too tough to read. Any example where you can show me how to calculate the area of a simply generated contour would be helpful.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您正在使用轮廓线返回的对象。 (每个级别都有 x 和 y 组件的未命名列表。)我本来希望在一个易于访问的位置找到它,但结果却找到了一个 pdf 文件,它提供了一个算法,我依稀记得看到过 http://finzi.psych.upenn.edu/R/library/PBSmapping/doc/PBSmapping-UG.pdf(参见 pdf 第 19 页,标记为“-11-”)(已添加注意:维基百科关于“多边形”的文章引用了测量员公式的讨论:http://www.maa.org/pubs/Calc_articles/ma063.pdf ,这证明了我使用 abs() 的合理性。)
构建一个示例:
级别 == 130 处的区域(选择它是因为没有两个 130 级别并且它不符合任何绘图边界)则为:
I'm going to assume you are working with an object returned by contourLines. (An unnamed list with x and y components at each level.) I was expecting to find this in an easy to access location but instead found a pdf file that provided an algorithm which I vaguely remember seeing http://finzi.psych.upenn.edu/R/library/PBSmapping/doc/PBSmapping-UG.pdf (See pdf page 19, labeled "-11-") (Added note: The Wikipedia article on "polygon" cites this discussion of the Surveyors' Formula: http://www.maa.org/pubs/Calc_articles/ma063.pdf , which justifies my use of abs().)
Building an example:
The area at level == 130 (chosen because there are not two 130 levels and it doesn't meet any of the plot boundaries) is then:
感谢@DWin提供了可重现的示例,以及
sos
(我最喜欢的R包!)和splancs
的作者...得到与@DWin相同的答案,即安慰。 (大概是相同的算法,但在
splancs
包中的 Fortran 例程中实现......)Thanks to @DWin for reproducible example, and to the authors of
sos
(my favourite R package!) andsplancs
...Gets the same answer as @DWin, which is comforting. (Presumably it's the same algorithm, but implemented within a Fortran routine in the
splancs
package ...)