{"id":13735194,"url":"https://github.com/AntoineGuillot2/D3partitionR","last_synced_at":"2025-05-08T11:32:37.559Z","repository":{"id":215776438,"uuid":"84002417","full_name":"AntoineGuillot2/D3partitionR","owner":"AntoineGuillot2","description":"R package to visualise interactively hierarchical data.","archived":false,"fork":false,"pushed_at":"2019-07-31T09:49:52.000Z","size":4185,"stargazers_count":40,"open_issues_count":14,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-03T03:04:34.722Z","etag":null,"topics":["cran","d3js","d3partitionr","data-visualization","package","r","r-shiny"],"latest_commit_sha":null,"homepage":"http://enhancedatascience.com/2017/09/20/d3partitionr-0-5-beta/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AntoineGuillot2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-05T21:09:43.000Z","updated_at":"2024-02-25T11:33:37.000Z","dependencies_parsed_at":"2024-01-07T21:54:56.768Z","dependency_job_id":null,"html_url":"https://github.com/AntoineGuillot2/D3partitionR","commit_stats":null,"previous_names":["antoineguillot2/d3partitionr"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntoineGuillot2%2FD3partitionR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntoineGuillot2%2FD3partitionR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntoineGuillot2%2FD3partitionR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntoineGuillot2%2FD3partitionR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AntoineGuillot2","download_url":"https://codeload.github.com/AntoineGuillot2/D3partitionR/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224727173,"owners_count":17359532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cran","d3js","d3partitionr","data-visualization","package","r","r-shiny"],"created_at":"2024-08-03T03:01:04.044Z","updated_at":"2024-11-15T03:31:33.102Z","avatar_url":"https://github.com/AntoineGuillot2.png","language":"JavaScript","funding_links":[],"categories":["Visualization","JavaScript"],"sub_categories":["Tree and Hierarchical Data"],"readme":"# D3 partition R 0.5.0\n\nD3 partition R is an R package to build interactive visualisation of nested data. Through easy to-use R functions (in a ggplot-like syntax) you will be able to plot and customise sunburst, treemap, circle treemap, icicle and partition chart. All the visualisations are interactive, zoom-able and based on the latest version of d3.js (V4).\n\n![Examples](inst/img/ExampleD3partitionR.gif?raw=true)\n\n## Installation\nThe package is now available on the CRAN.\n\n```rmethods to add data\ninstall.packages(\"D3partitionR\")\n```\n\n## Global structure of the package\n\nThe D3partitionR package uses a S3 class of object: D3partitionR objects. Two sets of methods are available, methods to add data (i.e. add_data, add_nodes_data, add_title) and methods to customise the chart (set_chart_type, set_labels_parameters, set_legend_parameter, ...).\nThese methods return a D3partitionR object which will be plotted and compiled by the plot method.\n\n## Examples\n\n### Simple chart using Titanic data\nFor this first example, we will use the [Titanic data from Kaggle](https://www.kaggle.com/c/titanic/data/)\n\n```R\n## Loading packages\nlibrary(\"data.table\")\nlibrary(\"D3partitionR\")\n\n## Reading data\ntitanic_data = fread(\"train.csv\")\n\n##Agregating data to have unique sequence for the 4 variables\nvar_names=c('Sex','Embarked','Pclass','Survived')\ndata_plot=titanic_data[,.N,by=var_names]\ndata_plot[,(var_names):=lapply(var_names,function(x){data_plot[[x]]=paste0(x,' ',data_plot[[x]])\n  })]\n\n## Plotting the chart\nlibrary(\"magrittr\")\nD3partitionR() %\u003e%\n  add_data(data_plot,count = 'N',steps=c('Sex','Embarked','Pclass','Survived')) %\u003e%\n  add_title('Titanic') %\u003e%\n  plot()\n```\nThe add_data function is used to specify the data.frame to use and the variables to use:\n\n  * count: The variable which will define the size of each nodes (in this example the number of passengers)\n  * steps: The different steps or levels to be plotted\n\n### Choice of the type of chart\n\nYou can easily change the type of chart with **set_chart type**.\n\n```R\n##Treemap\nD3partitionR() %\u003e%\n  add_data(data_plot,count = 'N',steps=c('Sex','Embarked','Pclass','Survived')) %\u003e%\n  set_chart_type('treemap') %\u003e%\n  plot()\n\n##Circle treemap\nD3partitionR() %\u003e%\n    add_data(data_plot,count = 'N',steps=c('Sex','Embarked','Pclass','Survived')) %\u003e%\n    set_chart_type('circle_treemap') %\u003e%\n    plot()\n```\n\n\n## Additional data for some nodes\n\nYou can also add additional data for some nodes. For instance you can add comments on the nodes where the Embarking location is provided using the function add_nodes_data.\n\n```R\nd3 = D3partitionR() %\u003e%\n  add_data(data_plot,count = 'N',tooltip=c('name','Location'),steps=c('Sex','Embarked','Pclass','Survived')) %\u003e%\n  add_nodes_data(list('Embarked S'=list('Location'='\u003ca href=\"https://fr.wikipedia.org/wiki/Southampton\"\u003eSouthampton\u003c/a\u003e'),\n                 'Embarked C'=list('Location'='\u003ca href=\"https://fr.wikipedia.org/wiki/Cherbourg-Octeville\"\u003eCherbourg\u003c/a\u003e'),\n                 'Embarked Q'=list('Location'='\u003ca href=\"https://fr.wikipedia.org/wiki/Cobh\"\u003eQueenstown\u003c/a\u003e')\n                 )\n                 )\nd3 %\u003e%\n  set_legend_parameters(zoom_subset = TRUE) %\u003e%\n  set_chart_type('circle_treemap') %\u003e%\n  set_tooltip_parameters(visible=TRUE, style='background-color:lightblue;',builder='basic') %\u003e% \n  plot()\n``` \n\nWith this code, the nodes Embarked S, Embarked C, Embarked Q will have additional data apended (the url of the wikipedia page of the location).\n![Examples](inst/img/additionalNodesInformation.png?raw=true)\n\n\n## Specification of additional variables and nodes data\n\n### Specify color, tooltips and labels variable\nThe add_data also contains parameters to specify the variables to used as:\n\n  * **color**: name of the color variable (the variable can be numeric or categorical).\n  * **label**: name of the label variable (the variable can be numeric or categorical).\n  * **tooltip**: vector of the variables to use in the tooltip (the variable can be numeric or categorical).\n\n```R\nD3partitionR() %\u003e%\n  add_data(data_plot,count = 'N',steps=c('Sex','Embarked','Pclass','Survived'),tooltip=c('name','N'),label='name',color='N') %\u003e%\n  set_chart_type('treemap') %\u003e%\n  plot()\n```\n\nThese variables should either be:\n\n  * the variable used as the count variable\n  * Variables provided in add_nodes_data\n  * Numeric variables from the data.frame used in add_data. In this last case, a named list of functions (or a list of length one, the function will then be applied to all the variables) should be provided for the variables.\n\n```R\ntitanic_data = fread(\"train.csv\")\n\n## Selecting variables\nvar_names = c('Sex','Embarked','Pclass','Survived')\n\n## Merging steps data and data with ages\ndata_plot = merge(titanic_data[,.N, by = c(var_names)], titanic_data[,.(mean_age=mean(Age,na.rm =TRUE), Survived_num=Survived), by=c(var_names)], by=var_names)\n\n##Improving steps naming\ndata_plot[,(var_names):=lapply(var_names,function(x){data_plot[[x]]=paste0(x,' ',data_plot[[x]])\n  })]\n\nD3partitionR()%\u003e%\n  add_data(data_plot,count = 'N',steps=c('Sex','Embarked','Pclass','Survived'),tooltip=c('name','N','mean_age'),label='name',color='Survived_num',aggregate_fun = list(mean_age=weighted.mean,Survived_num=weighted.mean)) %\u003e%\n  set_chart_type('treemap') %\u003e%\n  set_labels_parameters(cut_off=10) %\u003e%\n  plot()\n```\n![Examples](inst/img/exampleAggregationFunction.png?raw=true)\n\n## Modify the tooltips, lengends and labels parameters\n\nThe modification of legend, labels and tooltips parameters are easily done too.\n\n#### Legend\n\nTo modify the legend parameters, you need to use **set_legend_parameters**, it has three parameters.\n```R\n##Circle treemap\nD3partitionR()%\u003e%\n    add_data(data_plot,count = 'N',steps=c('Sex','Embarked','Pclass','Survived'))%\u003e%\n    set_legend_parameters(visible=T,zoom_subset=T,width=100)%\u003e%\n    plot()    \n```\nThe use of visible and width are obvious. On the other hand, the zoom_subset will enable or disable the filtering of the legend labels based on the current level of zoom. If the zoom_subset is set to TRUE, only the direct children of the current root are shown in the legend.\n\n#### Tooltips\n\nTo modify the tooltips parameters, you need to use **set_tooltip_parameters**, it has three parameters.\n\n```R\n##Circle treemap\nD3partitionR()%\u003e%\n    add_data(data_plot,count = 'N',steps=c('Sex','Embarked','Pclass','Survived'))%\u003e%\n    set_tooltip_parameters(visible=T,style='background-color:lightblue;',builder='basic')%\u003e%\n    plot()    \n```\nThe style argument is used to customise the tooltips using a CSS string. The builder parameter changes the type of tooltip using a js expression. Two builders are currently in the package ('basic' and 'table').\n\n#### Labels\n\nTo modify the labels parameters, you need to use **set_tooltip_parameters**, it has three parameters.\n\n```R\n##Circle treemap\nD3partitionR()%\u003e%\n    add_data(data_plot,count = 'N',steps=c('Sex','Embarked','Pclass','Survived'))%\u003e%\n    set_labels_parameters(visible=T,cut_off=3,style='fill:lightblue;')%\u003e%\n    plot()    \n```\nThe style argument is used to customise the labels using a CSS string. \nThe cut_off parameter is used to choose which proportion of the labels is to be shown. For instance if the cut-off is set to 3, only the labels belonging to a node with a size which is greater than 3% of the current root size will be displaued.\n\n#### Trail\n\nThe trail can only be enabled/disabled using **set_trail**\n\n#### Title\n\nA title can be added using **add_title which** has two parameters text to provide the text and style.\n\n```R\n##Circle treemap\nD3partitionR()%\u003e%\n    add_data(data_plot,count = 'N',steps=c('Sex','Embarked','Pclass','Survived'))%\u003e%\n    add_title(text='Titanic',style='font-size:20px;')%\u003e%\n    plot()\n```\n\n## D3.js code modularity\n\nThe d3.js code was thought to be modular, hence it is easy to add new chart types. Each chart type has its own .js file with its drawing function. In this file:\n\n  * The chart is plotted, the labels and the colors are added\n  * The function return a click behavior which is called when a node is clicked. This file is called in the general function in charge of drawing the chart, the legend, the title and the breadcrumb.\n\nHence any hierarchical-like d3.js visualisation can easily be generalised and added to the package\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAntoineGuillot2%2FD3partitionR","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAntoineGuillot2%2FD3partitionR","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAntoineGuillot2%2FD3partitionR/lists"}