2014-04-10 47 views
2

我試圖創建我自己的準shapefile並將其提供給ggplot2。我已經使用地圖包中的預製地圖數據完成了此操作。我無法創建繪製所有作品的shapefile。創建一個形狀文件:ggplot2

我希望所有的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") 

enter image description here

回答

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 

enter image description here

+0

你的意見是對現貨。我有一個數據集「01,02,03,......,09」,另一個數據集爲「1,2,3,...,9」。 –