# загрузка пакетов
library('data.table')
library('WDI')
library('leaflet')
# https://cran.r-project.org/bin/windows/Rtools/
# devtools::install_github('mages/googleVis')
suppressPackageStartupMessages(library('googleVis'))
# для загрузки свежей версии pandoc:
# https://github.com/pandoc-extras/pandoc-nightly/releases/tag/hash-7c20fab3
# архив pandoc-windows-7c20fab3.zip распаковать в RStudio/bin/pandoc
Интерактивная картограмма на данных Всемирного Банка по ВВП на душу населения в текущих ценах (долл. США) за 2019 год.
# данные по ВВП по ППП
indicator.code <- 'NY.GDP.PCAP.PP.CD'
DT <- data.table(WDI(indicator = indicator.code, start = 2019, end = 2019))
# все коды стран iso2
fileURL <- 'https://pkgstore.datahub.io/core/country-list/data_csv/data/d7c9d7cfb42cb69f4422dec222dbbaa8/data_csv.csv'
all.iso2.country.codes <- read.csv(fileURL, stringsAsFactors = F,
na.strings = '.')
# убираем макрорегионы
DT <- na.omit(DT[iso2c %in% all.iso2.country.codes$Code, ])
# объект: таблица исходных данных
g.tbl <- gvisTable(data = DT[, -'year'],
options = list(width = 300, height = 400))
# объект: интерактивная карта
g.chart <- gvisGeoChart(data = DT,
locationvar = 'iso2c',
hovervar = 'country',
colorvar = indicator.code,
options = list(width = 500,
height = 400,
dataMode = 'regions'))
# размещаем таблицу и карту на одной панели (слева направо)
TG <- gvisMerge(g.tbl, g.chart,
horizontal = TRUE,
tableOptions = 'bgcolor=\"#CCCCCC\" cellspacing=10')
# вставляем результат в html-документ
TG
|
|
data.frame
. R package version 1.14.0. https://CRAN.R-project.org/package=data.tableDynamic Graphics with the googleVis Package http://rpubs.com/gallery/googleVis
Дмитрий Храмов, «Сбор данных в Интернете на языке R». – М.: ДМК Пресс, 2017. – 280 с.
Документация по API Геокодера от Яндекс https://tech.yandex.ru/maps/doc/geocoder/desc/concepts/about-docpage/
Simon Munzert, Christian Rubba, Peter Meisner, Dominic Nyhuis Automated Data Collection with R. Wiley, 2015 https://books.google.ru/books?id=X-7sBQAAQBAJ&pg=PA96&lpg=PA96&dq=r+xml+xpath+returns+empty&source=bl&ots=OSnRWmFKTR&sig=ACfU3U2wE7shk3mFHrLrlMkFSfwvuAYpEg&hl=ru&sa=X&ved=2ahUKEwiu8_nVmrHhAhUMs4sKHe5vDFIQ6AEwCXoECAkQAQ#v=onepage&q=r%20xml%20xpath%20returns%20empty&f=false