【发布时间】:2018-09-08 03:17:35
【问题描述】:
我正在尝试用几何对象将我的 tibble 中的多面体替换为点。我正在使用sf 包进行绘图。由于几何数据点很多,因此很难给出可重现的样本。
但我不使用基础 R,而是使用 ggplot2,我的对象是带有 geometry 变量的 tibble。这是我的代码:
library(tidyverse)
library(sf)
utrecht_sf %>%
ggplot() +
geom_sf(aes(fill = partij),
size = 0.4,
colour = "white") +
coord_sf(datum = NA) +
scale_fill_colorblind() +
theme_minimal()
utrecht_sf
# A tibble: 43 x 12
stad postcode partij stemmen totaal_stemmen perct_grootste_van_totaal OBJECTID Aantal_mul Aantal_adr Shape_Leng Shape_Area geometry
<chr> <chr> <chr> <int> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <sf_geometry [m]>
1 Utrecht 3451 VVD 1612 6598 24 1074 1.00 4548 24960 7787919 MULTIPOLYGON (((127829.1 45.…
2 Utrecht 3452 VVD 1038 4013 26 1075 1.00 5239 8278 1938913 MULTIPOLYGON (((128499.4 45.…
3 Utrecht 3453 VVD 784 3135 25 1076 1.00 3422 8089 1617391 MULTIPOLYGON (((128803.5 45.…
4 Utrecht 3454 VVD 985 4609 21 1077 1.00 5591 31103 8025353 MULTIPOLYGON (((130358.6 45.…
5 Utrecht 3455 VVD 60 260 23 1078 1.00 202 16097 6880581 MULTIPOLYGON (((128011.3 46.…
6 Utrecht 3511 GROENLINKS 2948 9840 30 1087 1.00 6951 6808 1222881 MULTIPOLYGON (((136430.8 45.…
7 Utrecht 3512 GROENLINKS 1905 6528 29 1088 1.00 5454 5817 852599 MULTIPOLYGON (((137189.5 45.…
8 Utrecht 3513 GROENLINKS 746 2717 27 1089 1.00 3550 3294 517187 MULTIPOLYGON (((136097 4571.…
9 Utrecht 3514 GROENLINKS 882 2948 30 1090 1.00 3659 4900 590764 MULTIPOLYGON (((137373.3 45.…
10 Utrecht 3515 GROENLINKS 1240 4257 29 1091 1.00 2908 3014 473581 MULTIPOLYGON (((136393.6 45.…
生成以下图像:
将每个多边形变成一个我可以为其赋值的点的最简单方法是什么?非常感谢您的帮助。
【问题讨论】:
-
class(utrecht_sf)的结果是什么,您能告诉我们您尝试了什么以及收到了哪些错误消息吗? -
utrecht_sf是一个小标题,@SymbolixAU 下面的答案就像一个魅力!只有我在将两个消音器附加到点上时遇到了困难。
标签: r ggplot2 gis geospatial sf