Alex Karvouniaris
Alex Karvouniaris

Reputation: 343

choroplethr maps in R

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 .

Upvotes: 2

Views: 2180

Answers (1)

Ari
Ari

Reputation: 1970

I think that there are two things here.

  1. By default, all NA values in choroplethr are rendered as black:

    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)
    ...
    

default na

  1. Note that you can override the scale by this:

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

custom-scale

You said that you wanted the NA values to appear grey. You can do that too just by changing the value of the na.value. Here I chose yellow just for a large contrast because this is an example.

Upvotes: 5

Related Questions