【发布时间】:2019-06-16 23:48:52
【问题描述】:
我正在使用 R 中 rworldmap 包中的欧洲地图创建热图(因为我不知道如何使用 ggmap 或 ggplot2 来执行此操作)。
我只需要绘制出现在我的数据框中的国家的国家名称,而不是所有欧洲国家。我怎样才能做到这一点? 我的代码:
library(RColorBrewer)
#getting colours
colourPalette <- brewer.pal(5,'RdPu')
library(rworldmap)
europe <- data.frame(
"country" = c("Greece",
"France",
"Spain",
"Italy",
"UK",
"Finland","Norway","Sweden",
"Germany",
"Romania"),
"x" = c(2.5, 3, 2.2, 1.8,2.32, 1.99, 2.01, 2.34, 1.88, 2.45))
matched <- joinCountryData2Map(europe, joinCode="NAME", nameJoinColumn="country")
mapParams <- mapCountryData(matched,
nameColumnToPlot="x",
mapTitle="my Titley",
addLegend=FALSE,
mapRegion="Europe"
,colourPalette=colourPalette,
oceanCol="#404040", missingCountryCol="#A0A0A0")
#adding legend
do.call(addMapLegend
,c(mapParams
,legendLabels="all"
,legendWidth=0.5
,legendIntervals="data"
,legendMar = 2))
labelCountries()
使用labelCountries() 会打印所有国家/地区名称,但不可读。
谢谢
【问题讨论】: