2つのステップがありました。(1)データを集約し、(2)jsonに変換します。その後、すべてのjavascriptがそのサンプルページに書き込まれているので、結果のjsonデータをプラグインできます。
集計されたデータは、ツリーマップと同様の構造を持つ必要があるため、treemap
パッケージを使用して集約を行います(連続した集計でループを使用することもできます)。次に、d3treeR
(githubから)を使用してツリーマップデータを入れ子リストに変換し、jsonlite
を使用してリストをjsonに変換します。
パッケージにあるGNI2010
のサンプルデータを使用しています。すべてのソースファイルはplunkerにあります。私ものindex.htmlを起動して、光沢のあるバインディングを作成するには
が表示されるはずその後
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
に例index.html
でソース行を置き換え
library(treemap)
library(d3treeR) # devtools::install_github("timelyportfolio/d3treeR")
library(data.tree)
library(jsonlite)
## Get treemap data using package treemap
## Using example data GNI2010 from d3treeR package
data(GNI2010)
## aggregate by these: continent, iso3,
## size by population, and color by GNI
indexList <- c('continent', 'iso3')
treedat <- treemap(GNI2010, index=indexList, vSize='population', vColor='GNI',
type="value", fun.aggregate = "sum",
palette = 'RdYlBu')
treedat <- treedat$tm # pull out the data
## Use d3treeR to convert to nested list structure
## Call the root node 'flare' so we can just plug it into the example
res <- d3treeR:::convert_treemap(treedat, rootname="flare")
## Convert to JSON using jsonlite::toJSON
json <- toJSON(res, auto_unbox = TRUE)
## Save the json to a directory with the example index.html
writeLines(json, "d3circle/flare.json")
はなんとかする必要がありますhtmlwidgets
といくつかの例を使用してください(d3treeR
のソースにはいくつかあります)。色付けのように、特定のことが機能していないことに注意してください。ここに格納されているjsonには、実際にノードで使用される多くの情報(treemap
を使用して集計されたすべてのデータ)が含まれています。
いいですね。データ構造は、ツリーマップと同じになります(連続的に分割する文法変数と集約)。 timelyportfolioからgithub whit shinyバインディングのd3treeが入手可能です。 – jenesaisquoi