trulia/choroplethr

Europe states

Closed this issue · 4 comments

Thank you for your package which gives very nice data and very documented.

I would like to use your package with a European map in order to replicate a map like state_choropleth(df_pop_state)

Do you know if, how is it possible ? Would you recommand another packge ?

Yes, this is possible with choroplethr. Please see the documentation here:

https://cran.r-project.org/web/packages/choroplethr/vignettes/d-country-choropleth.html

I also provide more detail in the section "International Maps" on my course
"Mapmaking in R with Choroplethr":

http://courses.arilamstein.com/courses/mapmaking-r-choroplethr

On Wed, Mar 9, 2016 at 2:02 PM, Ouphix notifications@github.com wrote:

Thank you for your package which gives very nice data and very documented.

I would like to use your package with a European map in order to replicate
a map like state_choropleth(df_pop_state)

Do you know if, how is it possible ? Would you recommand another packge ?


Reply to this email directly or view it on GitHub
#39.

It works almost thank you with the code :

`#Replace the upper cases by lower cases
DF <- data.frame(namesLower, answering_countries, stringsAsFactors=FALSE)
names(DF) <- c("region", "value")
names(DF)
DF
str(DF)
DF[1:3,]

change serbia by republic of serbia

DF[which(DF$region=="serbia"),1] <- "republic of serbia"
DF

deleting malta which is not in your regions

DF <-DF[-which(DF$region=="malta"),]

country_choropleth(DF,
title = "2012 Population Estimates",
legend = "Population",
zoom = c("belarus", "croatia", "france", "republic of serbia","united kingdom", "switzerland", "albania", "estonia", "lithuania", "bosnia and herzegovina", "latvia", "bulgaria", "finland", "germany", "spain", "belgium", "israel", "greece", "italy", "czech republic", "slovenia", "france", "romania"))
`
I have 2 small problems. I can see the colonies of France very far from Europe wich are not relevant. I would like to keep only European data. Malta is not in your regions, I doubt it will change much since it is a small island. Thank you for your work !!

I would manually set the longitude and latitude to be what you want.
choroplethr uses ggplot2, so you can do it like this:

library(ggplot2)
country_choropleth(df_pop_country, zoom = countries) +
xlim(-20,30) + ylim(30, 75)

Regarding Malta: the course "Mapmaking in R with Choroplethr" goes into
much more detail about where this map comes from. My upcoming course will
go into much more detail about how to import and modify your own maps.

On Wed, Mar 9, 2016 at 3:08 PM, Ouphix notifications@github.com wrote:

It works almost thank you with the code :

`#Replace the upper cases by lower cases
DF <- data.frame(namesLower, answering_countries, stringsAsFactors=FALSE)
names(DF) <- c("region", "value")
names(DF)
DF
str(DF)
DF[1:3,]
change serbia by republic of serbia

DF[which(DF$region=="serbia"),1] <- "republic of serbia"
DF
deleting malta which is not in your regions

DF <-DF[-which(DF$region=="malta"),]

country_choropleth(DF,
title = "2012 Population Estimates",
legend = "Population",
zoom = c("belarus", "croatia", "france", "republic of serbia","united
kingdom", "switzerland", "albania", "estonia", "lithuania", "bosnia and
herzegovina", "latvia", "bulgaria", "finland", "germany", "spain",
"belgium", "israel", "greece", "italy", "czech republic", "slovenia",
"france", "romania"))
`
I have 2 small problems. I can see the colonies of France very far from
Europe wich are not relevant. I would like to keep only European data.
Malta is not in your regions, I doubt it will change much since it is a
small island. Thank you for your work !!


Reply to this email directly or view it on GitHub
#39 (comment).

It works perfectly thank you.
Here is my code
country_choropleth(DF,
title = "Participants of the study",
legend = "Number",
zoom = c("albania", "armenia", "austria", "azerbaijan", "belgium", "bosnia and herzegovina", "belarus", "bulgaria", "croatia", "cyprus" , "czech republic", "denmark", "greece", "estonia", "finland", "france", "georgia", "germany", "hungary", "iceland", "kazakhstan", "luxembourg", "netherlands", "norway", "ireland", "israel", "italy", "ireland", "latvia", "lithuania", "macedonia", "moldova", "montenegro", "poland", "portugal", "romania", "russia", "slovakia", "slovenia", "spain", "sweden", "switzerland", "united kingdom", "republic of serbia", "turkey", "ukraine")) + xlim(-20,30) + ylim(30,75)

It doesn't work with smaller countries an I deleted them this way DF <-DF[-which(DF$region=="malta" | DF$region=="andorra" | DF$region=="liechtenstein" | DF$region=="monaco" | DF$region=="san marino"),]

Thank you for this great work !!