使用ggplot2设置Voronoi单元格的最大尺寸。

问题描述 投票:0回答:1

可复制的例子。

    set.seed(123)
    x <- sample(1:30,9)
    y <- sample(1:30,9)
    points <- data.frame(x, y,
                         distance = sample(c("apples","pears","banana"), 9, replace = T))

# Plot
    ggplot(points) +
      geom_voronoi(aes(x=x,y=y,fill=distance)) +
      stat_voronoi(aes(x=x,y=y),geom = "path") +
      geom_point(aes(x=x,y=y))

使。

great

我想知道我是否可以限制Voronoi单元的大小 从x,y的最大距离,它是用来绘图的。我用油漆把这个敲起来。

some

有些人可能称之为艺术.

其中,单元格只能是如此之大,如果他们不与邻近的单元格相交。有什么想法吗?

为什么要这样做?我是用GPS数据来创建单元格,然后用系数给这些单元格上色。GPS坐标在空间上是不一致的,我不想给读者留下错误的印象。在我的真实数据中,有些单元格相当大。

r ggplot2 tidyverse voronoi
1个回答
1
投票

看来您使用的是一个略有不同的版本,但在0.3.1中,您可以通过使用 max_radius 参数。

library(ggforce)
#> Warning: package 'ggforce' was built under R version 3.6.2
#> Loading required package: ggplot2
library(ggplot2)
set.seed(123)
x <- sample(1:30,9)
y <- sample(1:30,9)
points <- data.frame(x, y,
                     distance = sample(c("apples","pears","banana"), 9, replace = T))

# Plot
ggplot(points, aes(x, y, group = -1L)) +
  geom_voronoi_tile(aes(fill=distance),
                    max.radius = 10,
                    colour = "black") +
  geom_point(aes(x=x,y=y))

于2020-04-14创建。重读包 (v0.3.0)

© www.soinside.com 2019 - 2024. All rights reserved.