d3treer / d3treer Goto Github PK
View Code? Open in Web Editor NEWR htmlwidget for d3.js treemaps
License: MIT License
R htmlwidget for d3.js treemaps
License: MIT License
I'm attempting to treemap the Trump campaign 2019 disclosures (n = 8737) and while treemap
will make a map, d3treeR returns the following error:
Error: 1: xmlParseEntityRef: no name
2: EntityRef: expecting ';'
3: EntityRef: expecting ';'
4: xmlParseEntityRef: no name
...and so on.
I pulled the data in from:
https://www.fec.gov/data/candidate/P80001571/?tab=spending&cycle=2020&election_full=False
(Disbursements)
then utilized this code:
trump<-read_csv("data//path")
trump %>%
group_by(entity_type_desc,recipient_name) %>%
mutate(amount = sum(disbursement_amount)) %>%
select(entity_type_desc, recipient_name, amount) %>%
mutate(log_amount = log(amount)) %>%
filter(amount >1000)-> trump2
trump2 %>%
arrange(-amount) %>%
distinct() %>%
View()
d3tree2(
treemap(
trump2,
index = c("entity_type_desc", "recipient_name"),
vSize="amount",
type = "value",
vColor = "amount"
)
)
Can the treemap be used as an input for a reactive variable or function - i.e. a table that filters based on the area of the treemap you click into?
In d3tree function (and not the d3tree2) I would like to have the option to have a tooltip that adds more info from the data that built the tree.
I see this enhancement but I couldnt get what I want from the answer. Can you help?
#4
I'm not sure if this is possible, but it would be really useful. Whenever you have a point estimate you also have a confidence interval that might be wide or tight. Visualizing that confidence interval is very important
Consider the following example:
library(treemap)
library(d3treeR)
data(business)
business$employees.growth <- business$employees - business$employees.prev
tm <- # Brewer's Red-White-Grey palette reversed with predefined range
treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
vColor="employees.growth",
type="value",
palette="-RdGy",
range=c(-30000,30000))
d3tree2( tm, rootname = "World" )
It would be great if when hovering over a rectangle 3 triangles and with 3 numbers appear in the legend. The numbers would be the point estimate and the bounds of the confidence interval.
Doable? Thanks!
Not a bug for your package, but treemap falls over with data.table 1.9.5
hello
i would like to make interactive treemaps with d3treeR but i cannot find the package. Can anyone help me?
thank you very much
You might know all about this already. When you print the object tmd3, as created in the code at the bottom of this comment, straight from the R console it correctly renders in the browser like this:
When it's rendered in a Shiny app, it looks like this:
It's trying to show all the levels at once, not just the top level of the hierarchy.
library(shiny)
library(treemap)
library(d3treeR)
library(htmlwidgets) # see https://github.com/timelyportfolio/d3treeR/issues/11
Var1 <- letters[1:5]
Var2 <- LETTERS[1:5]
Var3 <- c("Tiger", "Lion", "Bear", "Penguin", "Eagle", "Aardvark")
ThreeLevels <- expand.grid(Var1, Var2, Var3)
n <- nrow(ThreeLevels)
ThreeLevels$Size <- abs(rnorm(n, 12, 3))
ThreeLevels$Colour <- rnorm(n, 0, 1)
tm <- treemap(ThreeLevels, index = c("Var1", "Var2", "Var3"),
vSize = "Size", vColor = "Colour",
type = "value", palette = "Spectral",
fun.aggregate="weighted.mean")
tmd3 <- d3tree2(tm)
shinyApp(
ui = fluidPage(
sidebarLayout(
sidebarPanel(p("Hello world")),
mainPanel(d3treeOutput("tree"))
)
),
server = function(input, output) {
output$tree <- renderD3tree(tmd3)
}
)
Consider the example below, converting a {treemap} object for use by d3tree2. When you click down to the level where the value that has been given to vColor exists, Borduria looks like this:
The average value/color intuitively should be 2.6, hence a pale yellow/green, but instead we get purple/10, more or less aribtrarily (I'm not sure exactly why, but could imagine reasons).
It would be very useful if in this case the color assigned to the higher level rectangles was a weighted average of the values assigned to color the level below, until you reach the rectangles that have values actually assigned from originally. (I might have a crack at this myself down the track, but not in the immediate next few weeks.)
library(treemap)
library(d3treeR)
library(dplyr)
mock <- data.frame(
Country = rep(c("Ruritania", "Borduria"), 3),
Industry = rep(c("Accommodation", "Manufacturing", "Flower growing"), each = 2),
GDP = c(1000, 500, 20, 2000, 1800, 70),
Growth = c(-5, 4, -3, 2, -7, 10)
)
tm <- treemap(mock, index = c("Country", "Industry"), vSize = "GDP", vColor = "Growth",
type = "value", palette = "Spectral")
d3tree2(tm, rootname = "World")
# what should the country colours be? Probably mean vColor value, weighted by vSize:
mock %>%
group_by(Country) %>%
summarise(AvGrowth = round(sum(GDP * Growth) / sum(GDP), 1))
d3tree2(tree, rootname = "all")
where tree is a valid treemap object gives me this error:
Error in convert_treemap(data$tm, ifelse(!is.null(rootname), rootname, :
could not find function "as.Node"
Any ideas?
Thanks for the great work! I am trying to run the below example.
data(business)
business$employees.growth <- business$employees - business$employees.prev
d3tree3(
treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
vColor="employees.growth",
type="manual",
palette="-RdGy",
range=c(-30000,30000))
, rootname="Fictitious Business Data"
)
Was wondering if it is possible to disable the number at the top right
It also overlaps with the triangle pointer when the value gets large and the pointer value is no visible
Please correct me if I am wrong, I believe the grey bar is confidence level. Is it possible to disable it? It is there even if StdErr is not used in Treemap
Appreciate any advice. thanks.
@ignacio82, good questions and in this first iteration the answer for both is "no". However, accomplishing these is not all that difficult. See http://bost.ocks.org/mike/treemap/ for a very good treemap implementation. I actually prefer the click on parent as a way to zoom out. I find the gVis right + click less intuitive, but I'm sure that is a personal opinion.
I did not anticipate 10-layers deep hierarchies. It might be helpful to understand the use case here.
I'll think through how best to accomplish both a full view and a restricted-level view.
Thanks for the feedback.
Hey Thanks for this package. Any plan to put it on CRAN?
d3tree2Output("d3Tree", width = "82%", height="600px")
output$d3Tree <- renderD3tree2(d3tree2(
treemap(tree1,
index = c("department","aisle")
,vSize = "n"
,type = "index",
palette='Set3', width=700, height=700),
rootname = "General"
))
Hello.
I am back on treemaps with d3treeR. Thanks to you, i solved two problems i had previously (loops and white space between two treemaps).
Now, similarly, i have another problem, working in Rmarkdown environment.
I use {.tabset} to create a better reporting (see code below) and would like to have two treemaps separated this way.
The first one is displayed (treemap1) but not the second one ((treemap2)
treemap1
treemap2
I hope it is clear...
thank you in advance.
Pat
For example:
---
title: "test"
author: "Ignacio"
date: "9/23/2015"
output: html_document
---
## Original
```{r, echo=FALSE, warning=FALSE}
library(treemap)
library(d3treeR)
data(business)
business$employees.growth <-
business$employees - business$employees.prev
tm <-
treemap(
business,
index = c("NACE1", "NACE2"),
vSize = "employees",
vColor = "employees.growth",
type = "value",
palette = "RdYlGn",
range = c(-30000,30000),
fun.aggregate = "weighted.mean",
draw = F
)
tree <- d3tree2(tm, rootname = "World")
tree
```
Produces:
Dear Sirs,
I am a newbie in R and I came aross your project while searching for a way to visualize the composition of the EU parliament. I produced a simple df with the columns "country", "political faction", "local political party", "colour" (all char) and "number of EP members" (integer). It's pretty simple and I just want a standalone interactive version of the graph on a single html page. Treemap renders it perfectly but d3treeR output simply is blank. No errors or warnings are shown. I can save the project as a web page and all the data is present, but it doesn't render.
R version: 3.5.0
treemap: 2.4.2
d3treeR: 0.1
htmlwidgets: 1.2
I understand that d3treeR isn't in development any longer but maybe there could be some tweak I could apply to the html code? Any tip would be highly appreciated.
Please run this shiny app to see the problem. Simply change the input and new treemaps will appear, a new one for every update.
Best regards,
Stephen
# As you modify the rows of data being used from GNI (reactivity),
# multiple objects appear on the web page, one treemap per update
library(d3treeR)
library(treemap)
server <- function(input, output) {
# example 1 from ?treemap
data(GNI2010)
GNIR <- reactive({ GNI2010[1:input$rows, ] })
output$tree1 <- renderD3tree3({
tm <- treemap(GNIR()
,index=c("continent", "iso3")
,vSize="population"
,vColor="GNI"
,type="value"
)
d3tree3(tm, rootname = "World")
})
}
ui <- fluidPage(
numericInput("rows", "Rows from GNI?", 20, min = 5, max = 208),
d3tree3Output('tree1', height = "600px")
)
shinyApp(ui = ui, server = server)
I tried to download but it gives me
> install.packages("d3treeR")
Warning in install.packages :
package ‘d3treeR’ is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
For your info
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.4
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] ERAg_0.0.1.0000 ranger_0.13.1 spatialsample_0.1.0
[4] visdat_0.5.3 vip_0.3.2 finetune_0.1.0
[7] stacks_0.2.1 yardstick_0.0.8 workflowsets_0.1.0
[10] workflows_0.2.3 tune_0.1.6 tidyr_1.1.3
[13] tibble_3.1.4 rsample_0.1.0 recipes_0.1.16
[16] purrr_0.3.4 parsnip_0.1.7 modeldata_0.1.1
[19] infer_1.0.0 dials_0.0.9 scales_1.1.1
[22] broom_0.7.9 tidymodels_0.1.3 Boruta_7.0.0
[25] patchwork_1.1.1 superheat_0.1.0 gstat_2.0-7
[28] DataExplorer_0.8.2 ggfortify_0.4.12 ggbeeswarm_0.6.0
[31] rcompanion_2.4.1 report_0.3.5 ggridges_0.5.3
[34] GGally_2.1.2 corrr_0.4.3 ruler_0.2.4
[37] RColorBrewer_1.1-2 hablar_0.3.0 skimr_2.1.3
[40] dotwhisker_0.7.3 broom.mixed_0.2.7 readr_2.0.1
[43] threadr_0.9.126 lubridate_1.7.10 pillar_1.6.2
[46] treemap_2.4-3 lme4_1.1-27.1 Matrix_1.3-4
[49] ggExtra_0.9 DT_0.18 kableExtra_1.3.4
[52] data.table_1.14.0 knitr_1.33 pacman_0.5.1
[55] here_1.0.1 cowplot_1.1.1 see_0.6.7
[58] ggplot2_3.3.5 dplyr_1.0.7 assertthat_0.2.1
[61] stringr_1.4.0 stringi_1.7.3
loaded via a namespace (and not attached):
[1] insight_0.14.3 curl_4.3.2
[3] future_1.22.1 rpart_4.1-15
[5] rootSolve_1.8.2.2 DescTools_0.99.42
[7] desc_1.3.0 rprojroot_2.0.2
[9] dotCall64_1.0-1 fastmap_1.1.0
[11] spatstat.geom_2.2-2 furrr_0.2.3
[13] Rcpp_1.0.7 spam_2.7-0
[15] nloptr_1.2.2.2 rgeos_0.5-5
[17] png_0.1-7 networkD3_0.4
[19] rvest_1.0.1 xtable_1.8-4
[21] numDeriv_2016.8-1.1 forcats_0.5.1
[23] evaluate_0.14 wk_0.5.0
[25] htmlwidgets_1.5.3 classInt_0.4-3
[27] rstudioapi_0.13 latticeExtra_0.6-29
[29] magrittr_2.0.1 hardhat_0.1.6
[31] circular_0.4-93 downlit_0.2.1
[33] FNN_1.1.3 intervals_0.15.2
[35] distill_1.2 zip_2.2.0
[37] bslib_0.2.5.1 xfun_0.25
[39] miniUI_0.1.1.1 splines_4.1.1
[41] expm_0.999-6 testthat_3.0.4
[43] globals_0.14.0 backports_1.2.1
[45] GPfit_1.0-8 tools_4.1.1
[47] httr_1.4.2 units_0.7-2
[49] htmlTable_2.2.1 sessioninfo_1.1.1
[51] labeling_0.4.2 devtools_2.4.2
[53] cli_3.0.1 jpeg_0.1-9
[55] rworldxtra_1.01 vipor_0.4.5
[57] promises_1.2.0.1 parameters_0.14.0
[59] prettyunits_1.1.1 foreach_1.5.1
[61] bit64_4.0.5 cluster_2.1.2
[63] withr_2.4.2 stats4_4.1.1
[65] gld_2.6.2 crosstalk_1.1.1
[67] zoo_1.8-9 e1071_1.7-8
[69] foreign_0.8-81 pkgconfig_2.0.3
[71] diagis_0.1.5 spatstat.utils_2.2-0
[73] spatstat.data_2.1-0 memoise_2.0.0
[75] xml2_1.3.2 generics_0.1.0
[77] later_1.3.0 usethis_2.0.1
[79] hexbin_1.28.2 coda_0.19-4
[81] minqa_1.2.4 farver_2.1.0
[83] codetools_0.2-18 htmltools_0.5.2
[85] prodlim_2019.11.13 nortest_1.0-4
[87] grid_4.1.1 ggsignif_0.6.2
[89] xts_0.12.1 spacetime_1.2-5
[91] crayon_1.4.1 modeltools_0.2-23
[93] fansi_0.5.0 gower_0.2.2
[95] boot_1.3-28 survival_3.2-13
[97] gridExtra_2.3 lifecycle_1.0.0
[99] vctrs_0.3.8 cachem_1.0.6
[101] processx_3.5.2 highr_0.9
[103] repr_1.1.3 Formula_1.2-4
[105] base64enc_0.1-3 nnet_7.3-16
[107] munsell_0.5.0 deldir_0.2-10
[109] datawizard_0.2.0 fs_1.5.0
[111] rlang_0.4.11 ipred_0.9-11
[113] pkgbuild_1.2.0 digest_0.6.27
[115] checkmate_2.0.0 DiceDesign_1.9
[117] rmarkdown_2.10 fields_12.5
[119] yaml_2.2.1 coin_1.4-1
[121] haven_2.4.3 polyclip_1.10-0
[123] openxlsx_4.2.4 svglite_2.0.0
[125] callr_3.7.0 libcoin_1.0-8
[127] multcompView_0.1-8 remotes_2.4.0
[129] lmtest_0.9-38 lava_1.6.9
[131] matrixStats_0.60.1 bit_4.0.4
[133] vroom_1.5.4 shiny_1.6.0
[135] tzdb_0.1.2 Hmisc_4.5-0
[137] effectsize_0.4.5 colorspace_2.0-2
[139] lmom_2.8 viridisLite_0.4.0
[141] DBI_1.1.1 parallelly_1.27.0
[143] timeDate_3043.102 class_7.3-19
[145] glue_1.4.2 listenv_0.8.0
[147] nlme_3.1-152 MASS_7.3-54
[149] proxy_0.4-26 TH.data_1.0-10
[151] magick_2.7.3 R6_2.5.1
[153] maptools_1.1-1 plyr_1.8.6
[155] ggstance_0.3.5 gridBase_0.4-7
[157] gtable_0.3.0 pROC_1.17.0.1
[159] maps_3.3.0 webshot_0.5.2
[161] igraph_1.2.6 tidyselect_1.1.1
[163] iterators_1.0.13 lhs_1.1.1
[165] systemfonts_1.0.2 rworldmap_1.3-6
[167] lmerTest_3.1-3 mime_0.11
[169] httpuv_1.6.2 utf8_1.2.2
[171] jsonlite_1.7.2 lattice_0.20-44
[173] s2_1.0.6 keyholder_0.1.5
[175] sass_0.4.0 modelr_0.1.8
[177] ellipsis_0.3.2 reshape_0.8.8
[179] ps_1.6.0 viridis_0.6.1
[181] butcher_0.1.5 bayestestR_0.10.5
[183] hms_1.1.0 mvtnorm_1.1-2
[185] compiler_4.1.1 dbplyr_2.1.1
[187] sandwich_3.0-1 pkgload_1.2.1
[189] parallel_4.1.1 jquerylib_0.1.4
[191] sf_1.0-2 beeswarm_0.4.0
[193] sp_1.4-5 Exact_2.1
[195] rsconnect_0.8.24 KernSmooth_2.23-20
[197] multcomp_1.4-17
It would be useful to have some way of storing / communicating the result of a click on one of the rectangles, so as well as impacting on the d3 visualisation it could be used to modify other content of a Shiny app or web page. The aim being to make it easier to create this sort of functionality: http://www.mbie.govt.nz/what-we-do/business-growth-agenda/regions/web-tool-desktop#employee-count/retail-trade/christchurch from within the R/Shiny environment rather than hand coding JavaScript (which is what we did in that case).
Similar to this in networkD3 christophergandrud/networkD3#59 , which lets the user specify a JavaScript function to execute on click, which can then pass information on the clicked node to Shiny via Shiny.onInputChange() .
Getting a 404 error on: http://bl.ocks.org/mbostock/raw/4063269/flare.json
Start a separate issue solely to track progress on adding tooltips. See #2
I cannot get d3treeR to install and run in R version 3.5.3. Please advice. It says it needs gridSVG which isn't available for 3.5.3
devtools::install_github("timelyportfolio/d3treeR")
Installing package into ‘/Users/mhepner/Library/R/3.5/library’
(as ‘lib’ is unspecified)
ERROR: dependency ‘gridSVG’ is not available for package ‘d3treeR’
install.packages("gridSVG")
Installing package into ‘/Users/mhepner/Library/R/3.5/library’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘gridSVG’ is not available (for R version 3.5.3)
Hello,
I have an installation issue after running install_github("timelyportfolio/d3treeR"). See the error message below:
Error: package or namespace load failed for ‘d3treeR’ in get(Info[i, 1], envir = env):
lazy-load database '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/dplyr/R/dplyr.rdb' is corrupt In addition: Warning message:
In get(Info[i, 1], envir = env) : internal error -3 in R_decompress1
Thanks,
Volha
I tried to install d3TreeR several times
devtools::install_github("timelyportfolio/d3treeR")
But also get an error
Downloading GitHub repo timelyportfolio/d3treeR@master from URL https://api.github.com/repos/timelyportfolio/d3treeR/zipball/master Installing d3treeR "C:/PROGRA~1/R/R-33~1.1/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL \ "C:/Users/user/AppData/Local/Temp/RtmpwhPDEA/devtools1b6453806f/timelyportfolio-d3treeR-28c32e0" \ --library="C:/Users/user/Documents/R/win-library/3.3" --install-tests
* installing *source* package 'd3treeR' ... ** R ** inst ** preparing package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : there is no package called 'influenceR' ERROR: lazy loading failed for package 'd3treeR' * removing 'C:/Users/user/Documents/R/win-library/3.3/d3treeR' Error: Command failed (1)
As per discussion on Twitter, ability to control fonts with either CSS and R arguments
With a more complex treemap - say one with 4000 rows - the d3tree2 function takes impractibly long to convert from a treemap object. The final result renders fine - and not too slowly (just) on screen - but for practical purposes you want to create it once-off and save it; you certainly couldn't create it on the fly in a Shiny app. Also, it seems to take a surprisingly large amount of RAM, which makes me wonder if there is some kind of efficiency to be found somewhere. Example below is similar in size to a real world dataset for which the end result is ok, just very slow to generate. On my (not particularly high powered) machine the example below takes 66 seconds to create the original treemap object, 30 minutes to convert it to a d3 tree, and about 12 seconds to actually render it in a browser. The memory utilised shoots straight up to 4GB as soon as d3tree2() starts doing its thing, and then stays at that high level until R is shut down even though there are no objects of anywhere near that size in the R workspace.
library(treemap)
library(d3treeR)
library(dplyr)
Var1 <- letters[1:26]
Var2 <- LETTERS[1:26]
Var3 <- c("Tiger", "Lion", "Bear", "Penguin", "Eagle", "Aardvark")
biggish <- expand.grid(Var1, Var2, Var3)
n <- nrow(biggish)
biggish$Size <- abs(rnorm(n, 12, 3))
biggish$Colour <- rnorm(n, 0, 1)
system.time(
tm <- treemap(biggish, index = c("Var1", "Var2", "Var3"),
vSize = "Size", vColor = "Colour",
type = "value", palette = "Spectral",
fun.aggregate="weighted.mean")
)
system.time(
tmpd3 <- d3tree2(tm)
)
Dear developer,
I found when a conflict between the networkD3 and d3treeR, below is a reproducible example:
library(shiny)
library(plotly)
library(networkD3)
library(treemap)
library(d3treeR)
ui <- fluidPage(
plotlyOutput("p"),
forceNetworkOutput("o"),
d3treeOutput("a")
)
server <- function(input, output, session) {
output$p <- renderPlotly({
ds <- data.frame(labels = c("A", "B", "C"), values = c(10, 40, 60))
plot_ly(ds, labels = ~labels, values = ~values) %>%
add_pie() %>%
layout(title = "Basic Pie Chart using Plotly")
})
output$o <- renderForceNetwork({
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4, zoom = TRUE)
})
output$a <- renderD3tree({
data(GNI2014)
tm <- treemap(
GNI2014,
index=c("continent", "iso3"),
vSize="population",
vColor="GNI",
type="value"
)
d3tree( tm,rootname = "World" )
})
}
shinyApp(ui, server)
Is it possible to limit the overlapping of labels or make label font size relative to size of the box to prevent crowded and overlapping labels for treemaps using the d3tree3 function?
Although it exists in treemap, it looks like some of the options that are coded in treemap are lost when the d3tree function is added. For treemaps with numerous labels at the first level of aggregation (below the "NACE1", the treemap option lowerbound.cex.label = .5 and overlap.labels = 0 will clean up the presentation but when the d3tree3 is rendered in R the labels all reapprear using the default font size and will allow labels to overlap.
library(treemap)
library(d3treeR)
data(business)
business$employees.growth <- business$employees - business$employees.prev
tm <- # Brewer's Red-White-Grey palette reversed with predefined range
treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
vColor="employees.growth",
type="value",
palette="-RdGy",
overlap.labels = 0,
lowerbound.cex.labels = .5,
bg.labels = 0,
range=c(-30000,30000))
d3tree2( tm, rootname = "World" )
Hi - I am a newbie to Shiny and I am trying to use the d3TreeR HTML Widget
Sample Data:
Trader Dashboard Data Prep Sample.xlsx
I used the following code and it ran perfectly in R:
library(readxl)
budget_map <- read_excel(path = 'Trader Dashboard Data Prep Sample.xlsx',sheet='v2',col_names = TRUE)
library(treemap)
budget_treemap <- treemap(budget_map,index=c("Sales Agency","Agency","Advertiser"),vSize="Booked Revenue Net",vColor="Sales Agency",palette = "Set1",type="categorical",title="Australia Budget Map",fontsize.title=22)
library(d3treeR)
d3tree2(budget_treemap)
I'm trying to get it to render in Shiny and am using the following code:
library(shiny)
library(readxl)
library(treemap)
library(htmlwidgets)
library(data.tree)
library(d3treeR)
budget_map <- read_excel(path = 'C:/Users/rahul/Desktop/30k foot view/Trader Dashboard Data Prep Sample.xlsx',sheet='v2',col_names = TRUE)
budget_treemap <- treemap(budget_map,index=c("Sales Agency","Agency","Advertiser"),vSize="Booked Revenue Net",vColor="Sales Agency",palette = "Set1",type="categorical")
ui <- fluidPage(
d3tree2Output("au_budget_map")
)
server <- function(input,output){
output$au_budget_map <- renderD3tree2({budget_treemap})
}
shinyApp(ui = ui, server = server)
Not sure why it isnt rendering - any help will be greatly appreciated!
Hi,
I cannot use the latest dtreeR package with R v4.0.
I get the error message
Error: package or namespace load failed for ‘d3treeR’:
package ‘d3treeR’ was installed before R 4.0.0: please re-install it
Aare there any updates planned for the package so that it can run under R v4.0?
BR
Martin
Hi and thanks for the package,
I noticed a discrepancy in the colors of the rectangles, depending on the fact that it has children or not. Or maybe this is intended.
d3treeR::d3tree3('{
"name": "flare",
"color": "red",
"children": [
{
"name": "analytics",
"color": "blue",
"children": [
{
"name": "cluster",
"color": "green",
"children": [
{"name": "AgglomerativeCluster", "size": 3938, "color": "yellow"},
{"name": "CommunityStructure", "size": 3812, "color": "yellow"},
{"name": "HierarchicalCluster", "size": 6714, "color": "yellow"},
{"name": "MergeEdge", "size": 743, "color": "yellow"}
]
},
{
"name": "graph",
"color": "green",
"children": [
{"name": "BetweennessCentrality", "size": 3534, "color": "yellow"},
{"name": "LinkDistance", "size": 5731, "color": "yellow"},
{"name": "MaxFlowMinCut", "size": 7840, "color": "yellow"},
{"name": "ShortestPaths", "size": 5914, "color": "yellow"},
{"name": "SpanningTree", "size": 3416, "color": "yellow"}
]
},
{
"name": "optimization",
"color": "green",
"children": [
{"name": "AspectRatioBanker", "size": 7074, "color": "yellow"}
]
}
]
},
{
"name": "animate",
"color": "blue",
"children": [
{"name": "Easing", "size": 17010, "color": "green"},
{"name": "FunctionSequence", "size": 5842, "color": "green"},
{
"name": "interpolate",
"color": "green",
"children": [
{"name": "ArrayInterpolator", "size": 1983, "color": "yellow"},
{"name": "ColorInterpolator", "size": 2047, "color": "yellow"},
{"name": "DateInterpolator", "size": 1375, "color": "yellow"},
{"name": "Interpolator", "size": 8746, "color": "yellow"},
{"name": "MatrixInterpolator", "size": 2202, "color": "yellow"},
{"name": "NumberInterpolator", "size": 1382, "color": "yellow"},
{"name": "ObjectInterpolator", "size": 1629, "color": "yellow"},
{"name": "PointInterpolator", "size": 1675, "color": "yellow"},
{"name": "RectangleInterpolator", "size": 2042, "color": "yellow"}
]
},
{"name": "ISchedulable", "size": 1041, "color": "green"},
{"name": "Parallel", "size": 5176, "color": "green"},
{"name": "Pause", "size": 449, "color": "green"},
{"name": "Scheduler", "size": 5593, "color": "green"},
{"name": "Sequence", "size": 5534, "color": "green"},
{"name": "Transition", "size": 9201, "color": "green"},
{"name": "Transitioner", "size": 19975, "color": "green"},
{"name": "TransitionEvent", "size": 1116, "color": "green"},
{"name": "Tween", "size": 6006, "color": "green"}
]
}
]
}', celltext = "name")
Here I have a structure with 4 levels: first level is red, second level is blue, third level is green and fourth level is yellow.
When drawing the treemap, I can see that the top ribbon is indeed red but the two rectangles corresponding to the two elements at level 2 are green instead of blue. When I select the animate
element, the top ribbon turns blue, all rectangles that dont have children are green as I would expect but there is one element that is yellow, the one with children.
My question is then: is this expected to allow differentiation at the current level between elements that have children and elements that don't ?
Thank you
EDIT: I just noticed that the estimation of the best color fails in this case because it estimates the best color for the color of the current level, not the level of the children, you can see it by clicking on analytics
where white on yellow is hard to read. But selecting one of these elements drills down to the next level where the best color is correctly estimated as black.
Hi,
Less of an issue more a question of possibility.
I would like the final group to contain a couple of lines of information..
e.g.
customer: John Smith
telephone: 071234567
I'm struggling to add a new line, apologies if this is a simple question, I am rather new to the space
ui.R:
library(shiny)
library(DT)
library(treemap)
library(d3treeR)
library(parsetR)
shinyUI(fluidPage(
# Application title
titlePanel("Test"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
actionButton("actionButton",label = "Process")
),
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("Data", DT::dataTableOutput("dataTable")),
tabPanel("Visualization 1", d3tree2Output("d3Tree", width = "100%", height="600px")),
tabPanel("Visualization 2", parsetOutput("parset", width = "100%", height = "600px"))
)
)
)
))
server.R:
library(shiny)
library(DT)
library(treemap)
library(d3treeR)
library(dplyr)
library(parsetR)
library(htmlwidgets)
shinyServer(function(input, output) {
groupData <- eventReactive(input$actionButton,{
group <-
structure(
list(
location = structure(
c(
1L, 1L, 1L, 2L, 2L, 3L,
3L, 4L, 5L, 5L, 6L, 6L, 7L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L,
11L, 11L, 11L, 11L, 12L, 12L, 13L, 13L, 13L, 13L, 14L, 14L, 15L,
16L, 16L, 16L, 16L, 17L, 17L, 17L, 18L, 18L, 18L, 18L
), .Label = c(
"ATC",
"CN-DAINAM", "CN-GIALAI", "CN-LIENDANH", "CN-LONGAN", "CN-NGHEAN",
"DC-BACGIANG", "DC-BENTRE", "DC-CONGTHANH", "DC-DAINAM", "DC-DATLOC",
"DC-HAIDUONG", "DC-HUNGYEN", "DC-SSMOI", "DC-THIENNAM", "HN-BRANCH",
"HP-BRANCH", "SM-THAIBINH"
), class = "factor"
), level = structure(
c(
1L,
2L, 3L, 1L, 2L, 1L, 2L, 6L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 1L, 2L, 3L, 4L, 1L, 2L, 1L, 2L, 3L, 4L, 1L, 2L,
1L, 1L, 2L, 3L, 6L, 1L, 2L, 3L, 3L, 4L, 5L, 6L
), .Label = c("1",
"2", "3", "4", "5", "6"), class = "factor"
), amount = c(
13L,
62L, 20L, 29L, 81L, 3L, 10L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 9L,
2L, 10L, 3L, 2L, 21L, 27L, 26L, 355L, 7L, 1L, 6L, 11L, 4L, 5L,
6L, 3L, 8L, 34L, 1L, 44L, 135L, 1L, 2L, 13L, 9L, 2L, 5L, 5L,
4L, 4L
)
), class = "data.frame", row.names = c(NA,-45L), .Names = c("location",
"level", "amount")
)
return(group)
})
output$dataTable <- DT::renderDataTable(
datatable(
groupData(),filter = "top", rownames = FALSE,
extensions = 'ColVis',
options = list(
dom = 'C<"clear">lfrtip', autoWidth = TRUE,
lengthMenu = list(c(50, 100,-1), c('50', '100','All'))
)
) %>%
formatStyle(c('level'),
backgroundColor = styleInterval(
c(1,2,3,4,5,6),
c('brown','red',"lime","pink",
"yellow","cyan", "purple")
))
)
output$d3Tree <- renderD3tree2(d3tree2(
treemap(
groupData(),
index = c("location", "level"),
vSize = "amount",
vColor = "amount",
type = "value"
)
,rootname = "lohoi"
))
output$parset <- renderParset(parset(
as.data.frame(groupData()), dimensions = c("level", "location"),
value = htmlwidgets::JS("function(d){return d.amount}"),
tension = 0.5
))
})
The app runs fine on RStudio.
But when I deployed on Shiny server, it raised an error:
Log on shiny server:
Listening on http://127.0.0.1:53770
Attaching package: ‘DT’
The following objects are masked from ‘package:shiny’:
dataTableOutput, renderDataTable
Note: the specification for S3 class “AsIs” in package ‘jsonlite’ seems equivalent to one from package ‘RJSONIO’: not turning on duplicate class definitions for this class.
Loading required package: vcdExtra
Loading required package: vcd
Loading required package: grid
Loading required package: gnm
Attaching package: ‘dplyr’
The following object is masked from ‘package:vcdExtra’:
summarise
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
Error in (function (file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"), :
cannot open file 'Rplots.pdf'
Therefore, the tab which contains d3tree2Output could not render the plot with message:
Error: cannot open file 'Rplots.pdf'
The others tabs (DT and parsetR) were rendered correctly (though parsetR had problem stated here: timelyportfolio/parsetR#2)
R on the server is 3.2.1, all the packages using in the example are up to date.
Please let me know how to fix it.
Kind ragards
Is it possible to generate a treemap as an RDS file and then load it and plot it in an r markdown?
The following only render the treemap()
, not the d3tree2()
Minimal reproducible example:
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
library(treemap)
library(d3treeR)
data(GNI2014)
d3tree2(
treemap(
GNI2014
,index=c("continent", "iso3")
,vSize="population"
,vColor="GNI"
,type="value"
)
,rootname = "World"
)
```
I have not maintained since there has not been much indicated interest or usage. This package is in definite need of an update to d3v5
. Contributions are welcome.
Not sure if I am doing it in the wrong way or a bug
the height and width setting in d3tree or d3tree2 does not work in shiny, but works in Rstudio
This is the code in Rstudio:
##########################
data(business)
business$employees.growth <- business$employees - business$employees.prev
d3tree2(treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
vColor="employees.growth",
type="value",
palette="-RdGy",
range=c(-30000,30000)),
rootname = "Fictitious Business Data" ,
height = "1200px",
width = "50%")
#########################
This is the code for shiny:
########################
library(shiny)
library(treemap)
library(d3treeR)
ui <- fluidPage(
titlePanel("Treemap not sizable?"),
d3tree2Output('tree')
)
server <- function(input, output) {
data(business)
business$employees.growth <- business$employees - business$employees.prev
output$tree <- renderD3tree2({
d3tree2(treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
vColor="employees.growth",
type="value",
palette="-RdGy",
range=c(-30000,30000)),
rootname = "Fictitious Business Data" ,
height = "1200px",
width = "50%")
})
}
shinyApp(ui = ui, server = server)
I am getting confused at how to use clickActions. Is it possible to follow a link when the lowest level of a treemap is reached? Thanks for this great package!
Hi,
when I run the code for the first two examples on
http://www.buildingwidgets.com/blog/2015/7/17/week-28-d3treer
I get the following error:
Error in convert_treemap(data$tm, ifelse(!is.null(rootname), rootname, :
could not find function "as.Node"
I guess I either need a newer version of something or I'm missing a package? The treemap itself renders, but only as a static version. The d3.js flare example works thought, also in a Shiny app.
See below for my sessionInfo.
Hope you can help! Thanks in advance!
kind regards Herman
ps: great work on the htmlwidgets blog!
sessionInfo:
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252
[3] LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Netherlands.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] treemap_2.3 d3treeR_0.1 htmlwidgets_0.5 sortableR_0.1 shiny_0.12.1
loaded via a namespace (and not attached):
[1] bitops_1.0-6 chron_2.3-47 colorspace_1.2-6 curl_0.9.1 data.table_1.9.4
[6] data.tree_0.1.6 devtools_1.8.0 digest_0.6.8 ggplot2_1.0.1 git2r_0.10.1
[11] grid_3.1.3 gridBase_0.4-7 gtable_0.1.2 htmltools_0.2.6 httpuv_1.3.2
[16] httr_0.6.1 igraph_1.0.1 jsonlite_0.9.16 magrittr_1.5 MASS_7.3-40
[21] memoise_0.2.1 mime_0.3 munsell_0.4.2 plyr_1.8.3 proto_0.3-10
[26] R6_2.1.0 RColorBrewer_1.1-2 Rcpp_0.11.6 RCurl_1.95-4.5 reshape2_1.4.1
[31] rstudioapi_0.3.1 rversions_1.0.0 scales_0.2.5 stringi_0.5-5 stringr_1.0.0
[36] tools_3.1.3 XML_3.98-1.1 xtable_1.7-4 yaml_2.1.13
Hello.
I want to make interactive treemaps in R markdown. That is, produce one html file which contains several treemaps. My problem is : when i do one treemap, it is ok. When i make one loop with several treemaps for several analysis, it produces nothing.
Does anyone have any solution?
Thank you very much.
renderD3tree() depends on htmlwidgets::shinyRenderWidget() without specifying where it is, but {htmlwidgets} is only imported not loaded fully, so renderD3tree will only work in a Shiny app with {htmlwidgets} loaded explicitly.
This post should be deleted due to my mistake.
Start a separate issue regarding adding legends. See #2.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.