我想在R中使用filled.contour()绘制函数f(x,y),并添加一条直线/曲线来标识函数值为0的点。为了使示例可重复计算,假设我的函数的值是火山数据集中的值,而不是查找f(x,y) =0,我们希望添加一条直线/曲线来标识火山的值为500的位置。我该怎么做呢?下面的代码正确地在点X=500和Y=500.But添加了一个点,我如何添加一条直线,以便只有volcano=500的点被一条直线连接?我想只使用基础图形。
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)})
发布于 2015-02-12 00:34:24
一种不完美的解决方案:
#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)
可以通过将向量传递给参数level来指定多条等高线:level= c( 130 , 150 )将绘制高度为130和150的等高线
问题是filled.contour广告图例栏,因此简单地调用filled.contour然后调用轮廓会使这两张图片不匹配(请参阅帮助(filled.contour)中的说明)。
但是,使用此解决方案时,图例栏将会松动。
https://stackoverflow.com/questions/28458192
复制相似问题