D3plus

Projeto de uso e aplicação da ferramenta D3plus no R.

library(D3plusR)
library(dplyr)

data("trade_bra_chn")
head(trade_bra_chn)
##   Period Trade.Flow Reporter.Code Reporter Partner.Code Partner
## 1   2005     Export            76   Brazil          156   China
## 2   2005     Import            76   Brazil          156   China
## 3   2006     Export            76   Brazil          156   China
## 4   2006     Import            76   Brazil          156   China
## 5   2007     Export            76   Brazil          156   China
## 6   2007     Import            76   Brazil          156   China
##    TradeValue
## 1  6834996980
## 2  5354519158
## 3  8402368827
## 4  7989343057
## 5 10748813792
## 6 12617754515
d3plus(data = trade_bra_chn, # dados
       id = "Trade.Flow", # identificador das barras
       type = "bar", # gráfico de barras
       height = 400, # altura da visualização em px
       locale = "pt_BR", # definição de localização
       width = "100%") %>% # largura de 100%. Não é sempre necessário 
  d3plusX(value = "Period") %>% 
  d3plusY(value = "TradeValue") %>% 
  d3plusColor(value = "Trade.Flow") %>% 
  d3plusLegend(value = TRUE, size = 30, data = FALSE) %>% 
  d3plusTooltip(value = c("Period", "TradeValue")) %>% 
  d3plusTitle(value = "Exportações/Importações Brasileiras para/da China")

Including Plots

You can also embed plots, for example:

data("bra_exp_2015")

mapa <- system.file("extdata", "countries.topojson", package = "D3plusR")
mapa <- jsonlite::fromJSON(mapa, simplifyVector = F)

d3 <- d3plus(data = bra_exp_2015,
       type = "geo_map",
       id = "Partner.ISO",
       width = "100%",
       height = 500) %>% 
  d3plusCoords(mapa, projection = "equirectangular") %>% 
  d3plusColor(value = "Trade.Value..US..") %>% 
  d3plusTooltip(value = c("Trade.Value..US..", "Partner.ISO")) %>% 
  d3plusLabels(FALSE) %>% 
  d3plusText("Partner") %>% 
  d3plusTitle("Brazilian Exports Destinations") %>% 
  d3plusZoom(value = TRUE, scroll = FALSE) 

d3