Mapping the kingdom and non-kingdom countries. Now we get the map of UK with the country name on it! Not too difficult.ĭraw the map indicating coutries as kingdom or non-kingdom Map + geom_text(data = cnames, aes(x = long, y = lat, label = id), size = 4) + theme_void() map <- ggplot() + geom_polygon(data = shp, aes(x = long, y = lat, group = group), colour = "black", fill = NA) # Regions defined for each Polygons cnames <- aggregate(cbind(long, lat) ~ id, data=shp_df, FUN=mean) As we want to put the text on map, we need to explicitly tell the position of the text. “group” is a combination of id and a number. ![]() “id” comes from the region variable NAME_1 that is used in tidy function. “long” and “lat” are the coordinates of nodes. # "character" head(shp_df) # long lat order hole piece group id shp_df <- broom::tidy(shp, region = "NAME_1") We will tidy up the data, and create a ame. Fortunately, it is unique for each country! The attribute _NAME_1 is the country name. First, try to have some knowledge on the data. Now, we want to put the name of the four contries on the map. # Mode :character Mode :character Mode :character # Class :character Class :character Class :character # Integer64 fields read as strings: ID_0 ID_1 CCN_1 # ID_0 ISO NAME_0 # Source: "C:\Users\HUANFA~1\AppData\Local\Temp\RtmpeSSQIP/GBR_adm1.shp", layer: "GBR_adm1" Shp <- readOGR(dsn = file.path(tempdir(), "GBR_adm1.shp"), stringsAsFactors = F) # OGR data source with driver: ESRI Shapefile ![]() require(rgdal)įn <- file.path(tempdir(), "GBR_adm_gdb.zip", fsep = "\\") ![]() Now I will use an example to show the steps.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |