Choropleth maps with Highcharts and Shiny

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

内容简介: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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

数值方法和MATLAB实现与应用

数值方法和MATLAB实现与应用

拉克唐瓦尔德 / 机械工业出版社 / 2004-9 / 59.00元

本书是关于数值方法和MATLAB的介绍,是针对高等院校理工科专业学生编写的教材。数值方法可以用来生成其他方法无法求解的问题的近似解。本书的主要目的是为应用计算打下坚实的基础,由简单到复杂讲述了标准数值方法在实际问题中的实现和应用。本书通篇使用良好的编程习惯向读者展示了如何清楚地表达计算思想及编制文档。书中通过给读者提供大量的可直接运行的代码库以及讲解MARLAB工具箱中内置函数使用的数量方法,帮助......一起来看看 《数值方法和MATLAB实现与应用》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具