0

我使用 rworldmap 绘制了一张地图。但我无法插入带有扩展调色板的图例。我收到了这个错误:

图例错误(.... 未使用的参数(colourVector1 = "#00008B", colourVector2 = "#0B0B90", ...

这是我的代码:

library(rworldmap)
#color pallete
colours = colorRampPalette(c("darkblue", "white"))(23)

#csvfile
dF = read.csv("/home/shops.csv", header = T)

sPDF <- joinCountryData2Map(dF,
                            joinCode = "NAME",
                            nameJoinColumn = "Country",
                            verbose = TRUE)
mapData = mapCountryData(
  sPDF,
  nameColumnToPlot="Shops",
  mapTitle = "Number of facilities around the world",
  addLegend = F
  )
do.call( addMapLegendBoxes, c(mapData, cex=0.39,  x="left", colourVector = colours))

这是我的 csv 文件的一部分:

           Country Shops
1  United States   302
2        Germany    77
3 United Kingdom    67
4          Spain    60
5         France    44
6          China    35
4

1 回答 1

0

我使用ggmap自己解决了。这是解决方案:

library(ggplot2)
library(ggmap)
library(parallel)

#set workspace
setwd("/home/")
#Load data
df = read.csv("shops.csv", header = T)
coords = mclapply(X = as.character(df$Country), FUN= function(x) geocode(x))
coords=do.call(rbind.data.frame,coords)
df$lon = coords$lon
df$lat = coords$lat

mapWorld <- borders("world", colour="#E7E7E7", fill="#1a0000", alpha = .5)
mp <- ggplot() + mapWorld

mp <- mp+ geom_point(aes(x=df$lon, y=df$lat, size=df$Shops), alpha = .9, color="#000033")
mp <- mp + labs(size= "Number of shops")
mp <- mp + scale_size_continuous(breaks=c(5, 15, 26, 35, 44, 60, 67, 77, 302))
mp <- mp + theme(axis.title.x=element_blank(),
                 axis.text.x=element_blank(),
                 axis.ticks.x=element_blank(),
                 axis.title.y=element_blank(),
                 axis.text.y=element_blank(),
                 axis.ticks.y=element_blank())
mp

CSV 文件:

    Country Shops
1  United States   302
2        Germany    77
3 United Kingdom    67
4          Spain    60
5         France    44
6          China    35
...

阴谋

于 2017-07-01T16:11:42.137 回答