我正在尝试创建自己的准shapefile并将其提供给ggplot2。我使用地图包中的预制地图数据完成了这项工作。我无法创建一个绘制所有部分的shapefile。
我希望能够绘制所有id区域,但看起来我犯了一个错误,但我不明白如何或在哪里。这是当前的情节,缺少1到8件。
如何才能将这些缺失的部分绘制出来。这是数据:
space.manikin.shape <- structure(list(x = c(0.4, 0.4, 0.6, 0.6, 0.35, 0.4, 0.6, 0.65,
0.6, 0.65, 0.65, 0.6, 0.4, 0.35, 0.65, 0.6, 0.35, 0.35, 0.4,
0.4, 0.4, 0.4, 0.6, 0.6, 0.6, 0.6, 0.65, 0.65, 0.73, 0.73, 0.65,
0.65, 0.73, 0.73, 0.6, 0.6, 0.73, 0.73, 0.65, 0.65, 0.4, 0.4,
0.6, 0.6, 0.27, 0.27, 0.4, 0.4, 0.35, 0.35, 0.27, 0.27, 0.35,
0.35, 0.27, 0.27, 0.35, 0.35, 0.4, 0.4, 0.35, 0.35, 0.65, 0.65,
0.65, 0.65, 0.73, 0.73, 1, 1, 0.73, 0.73, 1, 1, 0.65, 0.65, 1,
1, 0.73, 0.73, 0.35, 0.35, 0.65, 0.65, 0, 0, 0.35, 0.35, 0.27,
0.27, 0, 0, 0.27, 0.27, 0, 0, 0.27, 0.27, 0.35, 0.35), y = c(0.67,
0.525, 0.525, 0.67, 0.75, 0.67, 0.67, 0.75, 0.525, 0.475, 0.75,
0.67, 0.525, 0.475, 0.475, 0.525, 0.75, 0.475, 0.525, 0.67, 0.87,
0.75, 0.75, 0.87, 0.87, 0.75, 0.75, 0.67, 0.67, 0.87, 0.67, 0.525,
0.525, 0.67, 0.475, 0.28, 0.28, 0.525, 0.525, 0.475, 0.475, 0.28,
0.28, 0.475, 0.525, 0.28, 0.28, 0.475, 0.475, 0.525, 0.67, 0.525,
0.525, 0.67, 0.87, 0.67, 0.67, 0.75, 0.75, 0.87, 1, 0.87, 0.87,
1, 1, 0.87, 0.87, 0.75, 0.75, 1, 0.75, 0.475, 0.475, 0.75, 0.28,
0, 0, 0.475, 0.475, 0.28, 0.28, 0, 0, 0.28, 0.475, 0, 0, 0.28,
0.28, 0.475, 0.75, 0.475, 0.475, 0.75, 1, 0.75, 0.75, 0.87, 0.87,
1), id = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L,
7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L,
13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 15L, 15L, 15L,
15L, 15L, 15L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L,
18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L,
20L, 21L, 21L, 21L, 21L, 21L, 21L), .Label = c("01", "02", "03",
"04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
"15", "16", "17", "18", "19", "20", "21"), class = "factor"),
order = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L,
1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L,
4L, 5L, 6L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 1L, 2L, 3L,
4L, 5L, 6L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 1L, 2L, 3L,
4L, 5L, 6L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 6L)), .Names = c("x",
"y", "id", "order"), class = "data.frame", row.names = c(NA,
-100L))
centers <- data.frame(
id = 1:21,
center.x=c(.5, .5, .625, .5, .375, .5, .66, .69, .66, .5, .34, .31,
.34, .5, .79, .815, .79, .5, .16, .135, .16),
center.y=c(.597, .71, .5975, .5, .5975, .82, .81, .6475, .39, .3775, .39,
.6475, .81, .935, .89, .6025, .19, .14, .19, .6025, .89)
)
library(ggplot2)
library(grid)
library(png)
ggplot(centers) + geom_map(aes(map_id = id), map = space.manikin.shape, colour="white") +
expand_limits(space.manikin.shape) +
geom_text(data=centers, aes(center.x, center.y, label = id), color="grey60")
答案 0 :(得分:1)
我不知道list_df2df
做了什么或做了什么包。
如果我使用polygon
使用我自己的解释,多边形看起来是正确的。另外,因为你丢失了多边形1:9,所以我怀疑多边形和中心id的匹配出了问题。多边形的名称为01
,02
等,而中心ID的名称为1
,2
等。这可能会导致您的问题。
polygon
的示例:
plot(0:1,0:1,type='n', ann=F, axes=T)
for (i in 1:length(dat)){
polygon(x=dat[[i]]$x, y=dat[[i]]$y, col=2)
text(x=centers[i,'center.x'], y=centers[i,'center.y'], labels=i)
}
# ... nothing wrong with polygon or center coordinates