【问题标题】:How to draw a level line in a filled contour plot and label it?如何在填充的等高线图中绘制水平线并标记它?
【发布时间】:2017-11-21 14:20:53
【问题描述】:

我有以下等高线图

x <- c(0,25,50,75,100)
y <- c(0,10,20)
z <- matrix(c(12,12,13,12,5,12,5,5,5,12,5,12,13,14,15), nrow = 5, ncol = 3, byrow = TRUE)
A <- matrix(seq(0, 100, by = 25), nrow = 3, ncol = 5, byrow = TRUE) #As x
B <- matrix(seq(0,20, by = 10), nrow = 3, ncol = 5) #As y
filled.contour(x,y,z, color=terrain.colors,#
  plot.axes = { axis(1); axis(2); points(A,B)})

如何在值为 5 的关卡周围绘制一条关卡线并对其进行标记并获得如下内容:

【问题讨论】:

    标签: r customization contour fill


    【解决方案1】:

    您可以在plot.axes 中使用contour。不可能在 5 处添加该行,因此我使用 5.01 代替并指定 labels。至少这是原则。

    filled.contour(x, y, z, color = terrain.colors,
                   plot.axes = {axis(1); axis(2); points(A, B);
                     contour(x, y, z, levels = 5.01, labels = "5", col = "red", add = TRUE)})
    

    【讨论】:

      【解决方案2】:
      library(fields)
      library(emdbook)
      
      x <- c(0,25,50,75,100)
      y <- c(0,10,20)
      z <- matrix(c(12,12,13,12,5,12,5,5,5,12,5,12,13,14,15), nrow = 5, ncol = 3, byrow = TRUE)
      A <- matrix(seq(0, 100, by = 25), nrow = 3, ncol = 5, byrow = TRUE) #As x
      B <- matrix(seq(0,20, by = 10), nrow = 3, ncol = 5) #As y
      
      
      image.plot(x,y,z)
      contour(x,y,z,
          add=TRUE, lwd=2, cex=2)
      

      【讨论】:

        猜你喜欢
        • 2015-01-01
        • 2019-12-13
        • 1970-01-01
        • 1970-01-01
        • 2023-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多