2

One more question about choropleth maps is coming . At first lets make some data.

`a<-c(4.1,2.5,0.4,6.4,1.4,1.8,3.8,1.3,2.3,8.4,5.2,1.9,0.8,1.5,2.1,1.2,3.8,1.4,3.1,0.8,4.0,1.3,4.8,2.6,2.8,2.3,3.1,2.5)
    target<-c("austria","belgium","bulgaria","switzerland","cyprus","czech republic","denmark",
"estonia","spain","finland","france","greece","croatia","hungary","ireland","italy",
"lithuania","luxembourg","latvia","norway","poland","portugal","romania","sweden",
"slovenia","slovakia","turkey","united kingdom")
datas<-data.frame(region=target,value=a)
datas$region<-as.character(datas$region)
install.packages("choroplethr")
install.packages("choroplethrMaps")
library(choroplethr)
library(choroplethrMaps)
data(country.map)
data(country.regions)


 gg <- country_choropleth(datas,legend="%",num_colors=1,zoom=target)
gg <- gg + xlim(-31.266001, 39.869301)
gg <- gg + ylim(27.636311, 81.008797)
gg <- gg + coord_map("lambert", lat0=27.636311, lat1=81.008797)
gg`

So the output is enter image description here

The thing that i cant adjust is to leave a country uncolored . If i set a country's value equal to 0 , that would drastically change the scale of the colors for the others. My target is to add countries that i don't have data for in the map and set their color to grey to make the map more realistic and to point out the countries that i have data for .

4

1 回答 1

5

我认为这里有两件事。

  1. 默认情况下,choroplethr 中的所有 NA 值都呈现为黑色:

    a <- c(NA, NA, NA,6.4,1.4,1.8,3.8,1.3,2.3,8.4,
           5.2,1.9,0.8,1.5,2.1,1.2,3.8,1.4,3.1,0.8,
           4.0, 1.3,4.8,2.6,2.8,2.3,3.1,2.5)
    ...
    

默认无

  1. 请注意,您可以通过以下方式覆盖比例:

    gg + scale_fill_continuous(low="#eff3ff", high="#084594", na.value="yellow")
    

定制规模

您说您希望 NA 值显示为灰色。您也可以通过更改na.value. 这里我选择黄色只是为了形成一个大的对比,因为这是一个例子。

于 2015-05-14T18:02:20.893 回答