香港赛马会彩券管理局

Bug when Creating Reference Maps with Choroplethr

May 21, 2019
By

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

Last week the Census Bureau published a free course I created on using Choroplethr to map US Census Data. Unfortunately, a few people have reported problems when following one of the examples in the course. This post describes that issues and provides instructions for working around it.

Where does the bug occur?

The bug occurs in Module 2 Lesson 4, when creating this map:

The code I provide to create that map can be seen here:

state_choropleth(df_pop_state,
    num_colors = 1,
    zoom = c("california", "oregon", "washington"),
    reference_map = TRUE)

Note that this map combines a standard choropleth (a map that uses color to indicate state population) with a reference map from Google maps (a map that shows terrain, large cities, and so on).

What’s the problem?

After I completed production of the course, google added a requirement that you must register an API key before getting their maps. Since Choroplethr requests reference maps without an API key, Google now refuses the request.

Behind the scenes, Choroplethr uses the ggmap package to request the maps. Here is how David Kahle, the author of ggmap, describes the issue in the help file for ggmap’s register_google function:

As of mid-2018, the Google Maps Platform requires a registered API key. While this alleviates previous burdens (e.g. query limits), it creates some challenges as well. The most immediate challenge for most R users is that ggmap functions that use Google’s services no longer function out of the box, since the user has to setup an account with Google, enable the relevant APIs, and then tell R about the user’s setup.

The help file goes into more detail, and I encourage you to read it.

Workaround

Getting the above example to work is a three step process.

1. Get an API key from Google by visiting the Google Maps Platform. This is free, although they require that you enter a credit card.

2. Register your key with the ggmap package by typing the following:

library(ggmap)
register_google("")

3. Install the mapproj package by typing the following

install.packages("mapproj")

Future Work

While the above steps solve the problem, I do not consider the fix to be particularly elegant. I am currently exploring other solutions, and will create a blog post if I find a better solution.

The post Bug when Creating Reference Maps with Choroplethr appeared first on AriLamstein.com.

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

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



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)
香港赛马会彩券管理局
四川金7乐网上开奖查询 一五年的3d开奖号码 乐利时时彩开奖号 大型电子游艺设备租赁 3d开豹子的历史记录 海南论坛天涯社区 北京pk10直播现场直播开奖记录 河南十一选五开奖视频 3d组三六码多少钱 好运来平特肖 两面针平特 中国牛彩彩搞网 安徽快三开奖号码官网 澳洲幸运10开奖机器人 湖南快乐十分钟开奖图