【发布时间】:2020-12-20 16:29:15
【问题描述】:
考虑一个我有四个多边形的示例数据集:
我希望多边形的颜色基于它所在的组、显示每种颜色含义的图例以及每个多边形上的标签及其门牌号。
以下代码行按组区分颜色:
plot(df$geometry, col=df$group)
来自上述示例的可重现数据:
structure(list(shape = c("polygon 1", "polygon 2", "polygon 3",
"polygon 4"), geometry = structure(list(structure(list(structure(c(0,
1, 1, 0, 0, 1, 1, 0, 0, 1), .Dim = c(5L, 2L))), class = c("XY",
"POLYGON", "sfg"), precision = 0, bbox = structure(c(xmin = 0,
ymin = 0, xmax = 1, ymax = 1), class = "bbox"), crs = structure(list(
input = NA_character_, wkt = NA_character_), class = "crs"), n_empty =
0L),
structure(list(structure(c(2, 3, 3, 2, 2, 3, 3, 2, 2, 3), .Dim = c(5L,
2L))), class = c("XY", "POLYGON", "sfg"), precision = 0, bbox =
structure(c(xmin = 2,
ymin = 2, xmax = 3, ymax = 3), class = "bbox"), crs = structure(list(
input = NA_character_, wkt = NA_character_), class = "crs"),
n_empty = 0L),
structure(list(structure(c(4, 5, 5, 4, 4, 4, 4, 5, 5, 4), .Dim = c(5L,
2L))), class = c("XY", "POLYGON", "sfg"), precision = 0, bbox =
structure(c(xmin = 4,
ymin = 4, xmax = 5, ymax = 5), class = "bbox"), crs = structure(list(
input = NA_character_, wkt = NA_character_), class = "crs"),
n_empty = 0L),
structure(list(structure(c(6, 7, 7, 6, 6, 7, 7, 6, 6, 7), .Dim = c(5L,
2L))), class = c("XY", "POLYGON", "sfg"), precision = 0, bbox =
structure(c(xmin = 6,
ymin = 6, xmax = 7, ymax = 7), class = "bbox"), crs = structure(list(
input = NA_character_, wkt = NA_character_), class = "crs"),
n_empty = 0L)), precision = 0, bbox = structure(c(xmin = 0,
ymin = 0, xmax = 7, ymax = 7), class = "bbox"), crs = structure(list(
input = NA_character_, wkt = NA_character_), class = "crs"), n_empty =
0L, class = c("sfc_POLYGON",
"sfc")), group = c(1, 1, 2, 2), house = c(1, 2, 3, 4)), row.names =
c(NA,
4L), class = c("sf", "tbl_df", "tbl", "data.frame"), sf_column =
"geometry", agr = structure(c(shape = NA_integer_,
group = NA_integer_, house = NA_integer_), class = "factor", .Label =
c("constant",
"aggregate", "identity")))
【问题讨论】:
标签: r plot shapes shapefile sf