R:UK NUTS1 Shapefile-ggplot(绘制最终图时缺少区域)

时间:2018-08-30 08:57:43

标签: r ggplot2 shapefile

我有以下代码,该代码将一个包含区域和值的csv文件,然后绘制地图:

MyData <- read.csv(file="D:\\Users\\NHoo01\\Desktop\\region.csv", header=TRUE, sep=",")
MyData$RD <- as.double(MyData$RD) #format as numeric

uk_shp <- readOGR("D:\\Users\\NHoo01\\Desktop\\NUTS1\\NUTS1.shp")

myDf <- fortify(uk_shp)

#rename columns for merging
names(myDf)[names(myDf) == "id"] <- "objectid"
names(MyData)[names(MyData) == "ï..nuts118nm"] <- "nuts118nm"

#merge dataframes
myDf2 <- merge(myDf, uk_shp@data, by="objectid")
myDf2 <- merge(myDf2, MyData, by="nuts118nm")

#create map plot and order it
Map_plot = myDf2[order(myDf2$order), ]

#plot the map
ggplot(Map_plot, aes(x = long.x, y = lat.x, group = group, fill = RD)) +
  geom_polygon() +
  coord_equal()

这将产生此结果:

enter image description here

由于某种原因,英格兰东北部不见了。

如果我看着Map_plot数据帧的开头,我会得到:

                   nuts118nm objectid   long.x    lat.x order  hole piece group nuts118cd  bng_e  bng_n
1    East Midlands (England)        4 537543.8 199883.1     1 FALSE     1   4.1       UKF 477660 322635
168          East of England        6 599964.1 346660.0     1 FALSE     1   6.1       UKH 571074 263229
715                   London        7 493941.1 254585.7     1 FALSE     1   7.1       UKI 517516 178392
1516    North East (England)        1 357136.2 587050.9     1 FALSE     1   1.1       UKC 417313 600358
2773    North West (England)        2 480000.0 517670.2     1 FALSE     1   2.1       UKD 350015 506280
3165                Scotland       11 116908.5 602925.2     1 FALSE     1  11.1       UKM 277746 700060
        long.y    lat.y  st_areasha st_lengths   RD
1    -0.849670 52.79572 15658181358   889656.3 2.07
168   0.504146 52.24067 19155125591  1083693.3 3.84
715  -0.308640 51.49227  1585475935   270855.1 1.20
1516 -1.728900 55.29703  8609938893   657578.2 1.24
2773 -2.772370 54.44945 14182609113  1063052.7 1.90
3165 -3.970910 56.17743 78634565219  9423683.3 1.74

因此,在绘制之前,东北已经在那里。我认为唯一的问题可能是东北是objectid = 1,当我绘制它时,第一个缺失了吗?

我应该提一下,如果我只是在绘制shp,那就是东北。

有什么建议吗?

0 个答案:

没有答案