Im trying to make a choropleth map of the european countries according to some metric (percentage of the population that have experienced an accident at work) using the new choroplethr package. Here's a reproducible example to demonstrate the 2 problems I need to solve.
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)
country_choropleth(datas,legend="%",num_colors=1,zoom=target)
1) The first profound problem that i come upon is these extra areas that belong to some countries(e.g france) and don't let the map zoom entirely on europe .
I gave zoom parameter the whole vector of the countries that exist in the data frame .
if i tried to
country_choropleth(datas,legend="%",num_colors=1,zoom="switzerland")
then it would zoom only on switzerland
The problem arrives from countries such as france where
country_choropleth(datas,legend="%",num_colors=1,zoom="france")
So i need a way to disengage the areas that belong to european countries and are not in the European area . Any ideas?
2) The second problem that i have is that inside country.regions$region
where the available regions to be used with the package exist , malta is missing. Its a single blot on the map , but still i cant skip it .
Is there any way to add a country ?
You should probably make this two questions. You can augment the output of the choropleth pkg with other ggplot
layers/aesthetics. To "zoom in" and use close to a proper projection you can do:
library(ggplot2)
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
(and you can play with the bounding box coords to get in a bit tighter)\