I think this comes down to an issue with appropriate sub-setting.
Your japanMapB
object consists of some metadata and a series of polygons for each shape stored in japanMapB@polygons
. So, you have:
> length(japanMapB$JCODE)
#[1] 1902
> length(japanMapB@polygons)
#[1] 1902
As @PaulHiemstra notes though, you have some NA
values in your JCODE
variable
> table(is.na(japanMapB$JCODE))
#FALSE TRUE
# 1894 8
Which means you get NA results when trying to index the municipalities you want to plot.
> table(japanMapB$JCODE==45382,useNA="always")
#FALSE TRUE <NA>
# 1893 1 8
Wrapping in which
solves this:
which(japanMapB$JCODE == 45382)
#[1] 1802
#You will now select to plot only the 1802th polygon stored in the data object
plot(japanMapB[which(japanMapB$JCODE == 45382),])