Quantcast
Channel: Search Results for “maps”– R-bloggers
Viewing all articles
Browse latest Browse all 589

New release: Choroplethr v3.2.0

$
0
0

(This article was first published on AriLamstein.com » R, and kindly contributed to R-bloggers)

Today I am happy to announce that a new version of choroplethr, v3.2.0, is now available. You can get it by typing the following from an R console:

install.packages("choroplethr")

Note that it sometimes takes a few days for new packages to get copied to each CRAN mirror. If install.packages(“choroplethr”) only gets you version 3.1.0, please try again tomorrow.

This version contains three changes.

Change #1: Better Default Projection

The most significant change is the addition of a better default map projection. I have discussed the issue of map projections in R at length here and here, among other places. Today I simply want to thank Hadley Wickham for pointing me to  coord_quickmap(), which gives you a nice projection that also works with insets. Here is a comparison between the old and new maps:

old-new-projection

library(choroplethr)
 
data(df_pop_county)
df_pop_county$value=NA

new = county_choropleth(df_pop_county, 
                        title = "New Default")

old            = CountyChoropleth$new(df_pop_county)
old$title      = "Old Default"
old$projection = element_blank()
old            = old$render()

library(gridExtra)
grid.arrange(new, old, ncol=2)

 

Change #2: Better Border Control

On maps with many small regions, the borders can obscure information. Look at the map below, which shows all the zip codes in New York state.

ny-zip-border-comp

In previous version of choroplethr it was hard to make the right-hand map. Choroplethr 3.2.0 simplifies this process quite a bit. It adds a ggplot_polygon member variable to the base Choropleth object. If you set it to geom_polygon(aes(fill=value), color=NA), as shown below, then the borders disappear:

library(choroplethrZip)
library(ggplot2)
data(df_pop_zip)

default = zip_choropleth(df_pop_zip, 
                         state_zoom = "new york",
                         title = "With Border") + 
            theme(legend.position="none")

c = ZipChoropleth$new(df_pop_zip)
c$title = "Without Border"
c$ggplot_polygon = geom_polygon(aes(fill = value), 
                                color = NA)
c$set_zoom_zip(state_zoom  = "new york", 
               county_zoom = NULL, 
               msa_zoom    = NULL, 
               zip_zoom    = NULL)

no_border = c$render() + 
              theme(legend.position = "none")

grid.arrange(default, no_border, ncol = 2)

Change #3: Continental US States

In my own work I frequently zoom in on the contiguous United States. I got tired of continually computing this vector of state names, so I added it as the variable continental_us_states. Here is an example:

continental

data(df_pop_county)        
data(continental_us_states)

county_choropleth(df_pop_county, 
                  state_zoom = continental_us_states)            

In Other News

On Tuesday I wrote a guest blog post titled Following up on news stories with choroplethr and R on the Revolution Analytics blog. In it I describe how I used R and choroplethr to research how fracking has changed the demographics of North Dakota. I first learned about this issue in an interview that Russ Roberts did with Gregory Zuckerman on the EconTalk podcast. The post is of technical interest because I demonstrate how to calculate the percentage change in census demographics.

LEARN TO MAP CENSUS DATA
Subscribe and get my free email course: Mapping Census Data in R!
100% Privacy. We don’t spam.

The post New release: Choroplethr v3.2.0 appeared first on AriLamstein.com.

To leave a comment for the author, please follow the link and comment on his blog: AriLamstein.com » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

Viewing all articles
Browse latest Browse all 589

Trending Articles