2012-02-23 95 views

回答

4

您正在尋找ATTR:

df[attr(df, "PolyData")$NAME_1 == 'Bumthang',] 

編輯:

將這項工作?

參數col代表顏色並鏈接到PID值。

df$Z='white' 
df[attr(df, "PolyData")$NAME_1 == 'Bumthang',]$Z ="red" 

plotPolys(df,col=df$Z) 

enter image description here

您也可以玩的,讓邊框的顏色ARG border。 如果你把它放在「白色」,那麼唯一顯示的區域將是布姆唐。

像這樣的工作:關於使用使用另一個庫子集文件

df$W = 'white' 
#borders of the region 
df[attr(df, "PolyData")$NAME_1 == 'Bumthang',]$W ="red" 
plotPolys(df,col=df$Z,border=df$W) 

enter image description here

+0

很抱歉,這是行不通的。但我不明白爲什麼。運行attr(df,「PolyData」)$ NAME_1確實爲我提供了NAME_1的值列表(包括'Bumthang')! – user702432 2012-02-23 08:43:04

+0

什麼是你想要達到的目標?我不清楚;這是地圖中的東西嗎?你能舉一個例子嗎?或者顯示一個小例子? – aatrujillob 2012-02-23 17:32:26

+0

PolySet數據有許多子區域。因此,如果您使用plotPolys(df),則會繪製包含所有子區域的整個地圖。我想要將特定的子區域子集化,然後繪製它:plotPolys(sub_df)或plotLines(sub_df)。 – user702432 2012-02-24 03:55:05

0

什麼?您可以使用rgdal對數據進行子集歸檔,保存到文件中,導入包含子集的shapefile並使用PBSMapping將其繪製。

library(rgdal) 
library(PBSmapping) 

df <- readOGR(".","df") 
subset <- df[df$NAME_1=="Bumthang",] 
writeOGR(subset, ".", "bumthang", driver="ESRI Shapefile") 
bum = importShapefile("bumthang.shp") 
plotPolys(bum, projection=TRUE) 

enter image description here

或者你可以用PBSmapping廢除乾脆。

plot(subset, axes=TRUE) 

enter image description here

相關問題