代码之家  ›  专栏  ›  技术社区  ›  sbac

如何在R中绘制开放多边形

  •  -3
  • sbac  · 技术社区  · 9 年前

    如何使用R创建开放多边形,如以下两个示例: Two open polygons

    2 回复  |  直到 9 年前
        1
  •  4
  •   Dave Gruenewald    9 年前

    geom_path 包装内 ggplot2 是一种相当简单的方法。

    x y 作为所有顶点的笛卡尔坐标:

    df <- data.frame(plot = c(rep(1, 3), rep(2, 4)),
                     x = c(1, 0, 2, 0.5, 0, 2, 2.5),
                     y = c(1, 0, 0, 1, 0, 0, 1))
    

    现在绘制:

    library(ggplot2)
    
    ggplot(data = df, aes(x = x, y = y, group = 1)) +
      geom_path(size = 1) + 
      facet_grid(. ~ plot) +
      theme_bw()
    

    enter image description here

    如果您希望定制更灵活,我建议您创建一个单独的、更详细的问题。

        2
  •  2
  •   Mosquite    9 年前

    如果您不想使用 ggplot 你可以对本地人做一件类似于“DaveGluenewald”的事情 plot 作用

    只要做:

    plot(c(0.5, 0, 2), c(1, 0, 0), type='l')
    plot(c(0.5, 0, 2, 2.5), c(1, 0, 0, 1), type='l')