0

我正在使用下面的代码生成带有连续变量的 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'))
4

0 回答 0