R:在轮廓图上添加一条线 [英] R: add a line to contour plot

查看:126
本文介绍了R:在轮廓图上添加一条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用R中的filled.contour()绘制函数f(x,y)并添加一条线/曲线以标识该函数的值为0的点。
使示例变得可写,假设我的函数的值是火山数据集中的值,而不是寻找f(x,y)= 0,我们想添加一条线/曲线来标识火山的值500。 b $ b我该怎么做?下面的代码正确地在点X = 500和Y = 500处添加了一个点,但是如何添加一条线,以便仅将volcano = 500的点通过一条线连接起来?我只想使用基本图形。

I would like to plot a function f(x, y) using filled.contour() in R and add a line/curve to identify the points where the value of the function is 0. In order to make the example repricable, let's say that the values for my function are those in the volcano dataset and instead of looking for f(x, y) = 0 we want to add a line/curve to identify where the volcano has value 500. How can I do this? The following code correctly adds a point at point X=500 and Y=500.But how can I add a line so that only points where volcano=500 are joint by a line? I would like to use only base graphics.

x <- 10*1:nrow(volcano)
y <- 10*1:ncol(volcano)
filled.contour(x, y, volcano, color = terrain.colors, plot.axes = { axis(1); axis(2); points(500, 500)})


推荐答案

一个不完美的解决方案:

One solution, which is not perfect:

#create a new plot
contour(x,y,volcano)
#use .filled.colour instead of filled.contour
.filled.contour(x, y, volcano,levels=seq(90,200,1),col=terrain.colors(109))
# add a contour plot with specific levels on top of the filled contour
contour(x,y,volcano, level=130,add=T)

您可以通过将vectoor传递到参数级别来指定几条轮廓线:level = c(130,150)将绘制高度为130和150的轮廓。

you can specify several contour lines by passing a vectoor to the argument level: level = c(130,150) will draw the contours for height 130 and 150

问题在于,fill.contour广告图例栏使您只需调用fill.contour然后轮廓即可使两张图片tch(请参阅help(filled.contour)中的注释)。

The problem is that filled.contour ads legend bar so that simply calling filled.contour and then contour makes that the two pictures does not match (see note in help(filled.contour)).

但是,使用此解决方案,您可以松开图例栏。

However, with this solution, you loose the legend bar.

这篇关于R:在轮廓图上添加一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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