Choropleth maps with Highcharts and Shiny

栏目: IT技术 · 发布时间: 4年前

内容简介:We use[code]]czo2MjE6XCJsaWJyYXJ5KHNoaW55KTxiciAvPgpsaWJyYXJ5KHNoaW55ZGFzaGJvYXJkKTxiciAvPgpsaWJyYXJ5KGhpZ2hjaGFydGV7WyYqJl19cik8YnIgLz4KbGlicmFyeShjb3VudHJ5Y29kZSk8YnIgLz4KbGlicmFyeShkcGx5cik8YnIgLz4KPGJyIC8+CnNhbGVzICZsdDstIHtbJiomXX1yZWFkLmNzdihcJ3NhbGV

We use Choropleth maps to show differences in colors or shading of pre-defined regions like states or countries, which correspond to differences in quantitative values like total rainfall, average temperature, economic indicators etc

Choropleth maps with Highcharts and Shiny In our case we will use sales of a toy making company, as quantitative value, in different countries around the world. See example with this

shiny app

Choropleth maps with Highcharts and Shiny
Highcharter is a  R  wrapper for  Highcharts

javascript based charting  modules.

Rendering Choropleth Maps with Highcharts in Shiny
  • To see Highcharts/Shiny interaction, we will begin by creating basic Shiny dashboard layout: It contains a single select widget and single tab for displaying map.

[code]]czo2MjE6XCJsaWJyYXJ5KHNoaW55KTxiciAvPgpsaWJyYXJ5KHNoaW55ZGFzaGJvYXJkKTxiciAvPgpsaWJyYXJ5KGhpZ2hjaGFydGV7WyYqJl19cik8YnIgLz4KbGlicmFyeShjb3VudHJ5Y29kZSk8YnIgLz4KbGlicmFyeShkcGx5cik8YnIgLz4KPGJyIC8+CnNhbGVzICZsdDstIHtbJiomXX1yZWFkLmNzdihcJ3NhbGVzcG9pbnQuY3N2XCcpPGJyIC8+CnVpJmx0Oy08YnIgLz4KPGJyIC8+CmRhc2hib2FyZFBhZ2UoPGJyIC8+CiB7WyYqJl19IGRhc2hib2FyZEhlYWRlcih0aXRsZSA9IFwiTWFwXCIpLDxiciAvPgo8YnIgLz4KICBkYXNoYm9hcmRTaWRlYmFyKDxiciAvPgogIHNpe1smKiZdfWRlYmFyTWVudSggPGJyIC8+CiAgc2VsZWN0SW5wdXQoXCd5ZWFyaWRcJyxcJ1NlbGVjdCBZZWFyXCcsY2hvaWNlcyA9IGMoMjAwMywyMDA0e1smKiZdfSwyMDA1KSxzZWxlY3RlZCA9ICAgIDIwMDMpIDxiciAvPgogICkpLDxiciAvPgo8YnIgLz4KICBkYXNoYm9hcmRCb2R5KDxiciAvPgp7WyYqJl19ICAgIHRhYkJveCh0aXRsZSA9IFwnVG95U2hvcFwnLGlkID0gXCd0YWJzZXQxXCcsd2lkdGggPSAxMiwgdGFiUGFuZWwoXCdXb3JsZC1TYWxle1smKiZdfXNcJyxoaWdoY2hhcnRPdXRwdXQoXCdjaGFydFwnLGhlaWdodCA9IFwnNTAwcHhcJykpKTxiciAvPgogICAgPGJyIC8+CiAgKTxiciAvPgopPHtbJiomXX1iciAvPgo8YnIgLz4KPGJyIC8+ClwiO3tbJiomXX0=[[/code]

  • In server function, filtering and summarize data with dplyr library and create a reactive object

[code]]czozOTI6XCJzZXJ2ZXIgJmx0Oy0gZnVuY3Rpb24oaW5wdXQsIG91dHB1dCwgc2Vzc2lvbil7PGJyIC8+CiAgPGJyIC8+CiAgdG90YWx7WyYqJl19ICZsdDstIHJlYWN0aXZlKDxiciAvPgogICAgezxiciAvPgogICAgc2FsZXMgJSZndDslPGJyIC8+CiAgICBmaWx0ZXIoWUVBUl9JRHtbJiomXX0gPT0gYXMubnVtZXJpYyhpbnB1dCR5ZWFyaWQpKSAlJmd0OyUgPGJyIC8+CiAgICBncm91cF9ieShDT1VOVFJZKSAlJmd0OyU8YnIge1smKiZdfS8+CiAgICBzdW1tYXJpemUoXCJUT1RBTF9TQUxFU1wiID0gYXMuaW50ZWdlcihzdW0oU0FMRVMpKSkgJSZndDslIDxiciAvPgogICAgbXtbJiomXX11dGF0ZShpc28zID0gY291bnRyeWNvZGUoQ09VTlRSWSxcImNvdW50cnkubmFtZVwiLFwiaXNvM2NcIikpPGJyIC8+CiAgICB9PGJyIC8+CntbJiomXX0gICAgKTxiciAvPgo8YnIgLz4KXCI7e1smKiZdfQ==[[/code]

Here we used library countrycode to convert long country names into one of many coding schemes. Adding new column iso3 in the summarized data with mutate function.

  • Passing reactive object in renderHighchart function. Customizing tooltip and sub-title content with reactive widgets.

[code]]czo4NDM6XCJvdXRwdXQkY2hhcnQgJmx0Oy0gcmVuZGVySGlnaGNoYXJ0KGhpZ2hjaGFydCh0eXBlID0gXCJtYXBcIikgJSZndDslIDxicntbJiomXX0gLz4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgPHN0cm9uZz5oY19hZGRfc2VyaWVzX21hcChtYXAgPSB3b3Jse1smKiZdfWRnZW9qc29uLCBkZiA9IHRvdGFsKCksIHZhbHVlID0gXCJUT1RBTF9TQUxFU1wiLCBqb2luQnkgPSBcImlzbzNcIik8L3N0cm9uZz4gJSZne1smKiZdfXQ7JSA8YnIgLz4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaGNfY29sb3JBeGlzKHN0b3BzID0gY29sb3Jfc3R7WyYqJl19b3BzKCkpICUmZ3Q7JSA8YnIgLz4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgPHN0cm9uZz5oY190b29sdGlwKHtbJiomXX11c2VIVE1MPVRSVUUsaGVhZGVyRm9ybWF0PVwnXCcscG9pbnRGb3JtYXQgPSBwYXN0ZTAoaW5wdXQkeWVhcmlkLFwnICB7cG9pbnQuQ09Ve1smKiZdfU5UUll9IFNhbGVzIDoge3BvaW50LlRPVEFMX1NBTEVTfSBcJykpPC9zdHJvbmc+ICUmZ3Q7JSA8YnIgLz4KICAgICAgICAgICAgICAge1smKiZdfSAgICAgICAgICAgICAgICAgICAgIGhjX3RpdGxlKHRleHQgPSBcJ0dsb2JhbCBTYWxlc1wnKSAlJmd0OyUgPGJyIC8+CiAgICAgICAgIHtbJiomXX0gICAgICAgICAgICAgICAgICAgICAgICAgICBoY19zdWJ0aXRsZSh0ZXh0ID0gcGFzdGUwKFwnWWVhcjogXCcsaW5wdXQkeWVhcmlkKSl7WyYqJl19ICUmZ3Q7JSA8YnIgLz4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaGNfZXhwb3J0aW5nKGVuYWJsZWQgPSBUUntbJiomXX1VRSxmaWxlbmFtZSA9IFwnY3VzdG9tXCcpPGJyIC8+CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICkgPGJyIC8+Cn17WyYqJl19PGJyIC8+CjxiciAvPgpcIjt7WyYqJl19[[/code]

Dataset and shiny R file can be downloaded from

here


以上所述就是小编给大家介绍的《Choropleth maps with Highcharts and Shiny》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

智能主义

智能主义

周鸿祎 / 中信出版集团股份有限公司 / 2016-11-1 / CNY 49.00

大数据和人工智能迅猛发展,对社会和商业的影响日益深刻,从学术界到企业界,智能化时代必将来临,已经成为共识。而此次变革,将会开启新一轮的发展浪潮。企业家、互联网以及传统企业、个人,应当如何理解这一轮的发展,如何行动以抓住智能化所带来的众多机遇,成为所有人持之以恒的关注热点。 周鸿祎作为最具洞察力的互联网老兵、人工智能领域成功的先行者,通过总结360公司的战略布局、产品规划、方法论实践,从思想到......一起来看看 《智能主义》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

MD5 加密
MD5 加密

MD5 加密工具

SHA 加密
SHA 加密

SHA 加密工具