我使用下面的代码生成带有连续变量的shapefile图。我想在虚线或点状多边形上叠加额外信息。关于如何做的任何想法?
prepShp4plot <- function(inShp){
inShp$id <- as.numeric(1:NROW(inShp))
inShp.fort <- fortify(inShp, region = "id")
countryDf <- join(inShp.fort,inShp@data)
}
# Load the required packages
library(plyr)
library(rgdal)
library(ggplot2)
library(rworldmap)
# FOR CLARITY in this example, let's import a shapefile from the rworldmap package
inShp <- getMap(resolution="coarse")
# Load the shapefile of interest
#shpDir <- '/home/whiteguru/path2shp'
#setwd(shpDir)
#inShp <- readOGR(dsn='.','world_boundary')
# Use a small function that prepares your polygon shapefile to be displayed
countryDf <- prepShp4plot(inShp)
ggplot(data = countryDf, aes(x = long, y = lat, fill = as.numeric(POP_EST), group = group)) +
geom_polygon(colour = "black") +
coord_equal() +
coord_map()+
theme(panel.background = element_rect(fill='#EBF4FA', colour='black'))+
scale_fill_gradientn('Human population\n',
limits=c(min(na.omit(countryDf$POP_EST)),max(na.omit(countryDf$POP_EST))),
colours=c("red","yellow","darkgreen"),
breaks=c(min(na.omit(countryDf$POP_EST)),
mean(na.omit(countryDf$POP_EST)),
max(na.omit(countryDf$POP_EST))),
labels = c('Very Small\n','Small\n','Large\n'))