mtennekes / treemap Goto Github PK
View Code? Open in Web Editor NEWR package for treemap visualisation
R package for treemap visualisation
I have been told that treemaps are not well displayed in RStudio using macOS. Someone able to confirm this, and find out why?
I was playing with treemaps in R and when I try categorical treemap, the treemap shows only one category. I wanted to reproduce treemap examples in Tableau but the categorical example is not giving me a correct treemap. The data is public and it is from Tableau website. It can be downloaded from[ here]. The treemap below shows only one category but the data has four categories.
(https://community.tableau.com/servlet/JiveServlet/downloadBody/1236-102-1-1149/Sample%20-%20Superstore%20Sales%20(Excel).xls).
`library(readxl)
library(dplyr)
Sample_Superstore <- read_excel("Sample_Superstore.xls")
grouped=Sample_Superstore%>%select(Sub-Category
,Sales,Ship Mode
)%>%
group_by(Sub-Category
,Ship Mode
)%>%summarise(Total_Sales=sum(Sales))
treemap(grouped,
index="Sub-Category",
vSize="Total_Sales",
vColor="Ship Mode",
type="categorical"
)`
Hey,
great package, it's more flexible than any software I tried to create a treemap! Thanks for the good work.
I've got a small problem, though: I cannot figure out how to change the color of the labels. I don't really want to activate the bg.labels, but when I deactivate them the labels are mixed between black and white. Is there any possibility to force treemap to draw all label texts in white, for example?
Thanks in advance,
Malte
Hi, in the documentation under "Usage" it reads that the default option of title is NA. However, by default the title does show. I guess it should read that in order to 'hide' the title you should set title to ""
library(treemap)
data(business)
treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
vColor="employees.prev",
type="comp",
palette="RdBu",
title = NA) # shows title
treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
vColor="employees.prev",
type="comp",
palette="RdBu",
title = "") # hides title
Warning messages:
1: In [.data.table
(dtfDT, , :=
("c", fact), with = FALSE) :
with=FALSE ignored, it isn't needed when using :=. See ?':=' for examples.
Not sure whether to report this here or for shinyapps but I think it's something about the {treemap} package that is problematic. To demonstrate the problem, I added the line library(treemap)
and nothing else to one of the basic shiny examples. The code below shows that it deploys to shinyapps fine when I have the CRAN version of treemap on my system, but not when I have the GitHub version. shinyapps works by mimicking your local install on RStudio's shiny server, so this shows that the problem is that it can't build the GitHub version of {treemap} for some reason.
This particularly causes the user problems just at the moment because the GitHub version of {treemap} is needed for {d3treeR} to work.
library(shiny)
library(shinyapps)
library(devtools)
install.packages("treemap") # ie from cran
# this works fine:
deployApp("C:/Users/Peter Ellis/Documents/R/win-library/3.1/shiny/examples/01_hello", account = "ellisp")
install_github("mtennekes/treemap/pkg") # ie from GitHub, dev version
runApp("C:/Users/Peter Ellis/Documents/R/win-library/3.1/shiny/examples/01_hello") # still works locally
# but this no longer works:
deployApp("C:/Users/Peter Ellis/Documents/R/win-library/3.1/shiny/examples/01_hello", account = "ellisp")
Which returns:
Error: Unhandled Exception: Child Task 73069206 failed: Error building image: Error building treemap (2.3). Build exited with non-zero status: 1
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_New Zealand.1252 LC_CTYPE=English_New Zealand.1252 LC_MONETARY=English_New Zealand.1252 LC_NUMERIC=C
[5] LC_TIME=English_New Zealand.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] treemap_2.3 shiny_0.12.2 devtools_1.8.0 shinyapps_0.3.63
loaded via a namespace (and not attached):
[1] bitops_1.0-6 Cairo_1.5-6 chron_2.3-47 colorspace_1.2-6 curl_0.9 data.table_1.9.4 digest_0.6.8 ggplot2_1.0.1
[9] git2r_0.10.1 grid_3.1.2 gridBase_0.4-7 gtable_0.1.2 htmltools_0.2.6 httpuv_1.3.3 httr_1.0.0 igraph_1.0.1
[17] jsonlite_0.9.16 magrittr_1.5 MASS_7.3-42 memoise_0.2.1 mime_0.3 munsell_0.4.2 plyr_1.8.3 proto_0.3-10
[25] R6_2.1.1 RColorBrewer_1.1-2 Rcpp_0.12.0 RCurl_1.95-4.7 reshape2_1.4.1 RJSONIO_1.3-0 rversions_1.0.1 scales_0.3.0
[33] stringi_0.5-5 stringr_1.0.0 tools_3.1.2 xml2_0.1.1 xtable_1.7-4
Hi,
I love the treemap as a cool initial explorative data analysis visualisation and the treemap function is excellent! I am currently building a website using Distill for RMarkdown and wish to include some of my treemaps, however, I cannot find a code-friendly way to save my treemap outputs into a png that I can plot on my website.
Any solution. Thank you!
Currently, I have this in my R markdown where I make a treemap, turn it into an interactive form using d3tree
{r Splitting ERA data and viewing proportions of practices for themes in all ERA data, code_folding=TRUE, layout="l-body-outset", fig.width=12, fig.height=10, fig.cap="Proportion of ERA theme and practices"}
# Lets split these
ERA.Compiled.Split <- ERAComboSplit(Data = ERAg::ERA.Compiled) # Using the ERAComboSplit function inherently from the ERAg package to “split” these practice and product combinations into duplicate individual rows each contain a unique combination of any practice x product combination present in the original observation.
# First we count the number of studies per level of the practice hierarchy (see PracticeCodes object for more information on the practice hierarchy)
ERA.Compiled.Split.Pracs <- ERA.Compiled.Split[,list(N.Studies=length(unique(Code))),by=list(SubPrName.Combo,PrName.Combo,Theme.Combo)]
# Visualize with the treemap function
# Proportions of ERA Theme data treemap
# Using the "Set2" colour palette from RColorBrewer
ERA_tree_theme_practices <- (treemap::treemap(ERA.Compiled.Split.Pracs,
index=c("Theme.Combo","PrName.Combo"),
vSize="N.Studies",
type="index",
palette = "Set2",
border.col=c("black","white"),
border.lwds=c(5,1),
fontsize.title=12,
title="Proportion of ERA theme and practices based on the number of studies for each ERA theme and practice"))
# Interactive treemap using the d3treeR package function d3tree()
ERA_tree_theme_practices_d3viz <- d3tree(ERA_tree_theme_practices)
# saving the treemap using save_d3_html() function from the package r2d3
save_d3_png(ERA_tree_theme_practices_d3viz, file = "ERA_tree_theme_practices_d3viz.png")
and when I try to save the interactive d3 treemap I get this:
This was the only way I could find to save my treemap yet I am sure there is a more straight forward one..?
For some simple datasets the value given for "vColor" in the call to itreemap() seems to be ignored. I posted an example to StackOverflow, but nobody was able to solve the issue. Note that it is possible to use the interface to set the vColor variable as desired, the only problem is that the initial state of the interactive treemap is not as specified. The stackoverflow post is at
All the boxes except the final (smallest), the routine appears to change type size etc to fit into the box. The final smallest one doesn't seem to try hard enough to fit the text.
Codeless (sorry I'll try to make a minimal sufficient code example later):
Please add an option to assign a specific color for the NA's
Hello,
I tried several ways to install the dev version on GitHub but none worked. Can you help me? Thanks!
version R version 4.1.0 (2021-05-18)
os Windows 10 x64
system x86_64, mingw32
ui RStudio
R> library(devtools)
Loading required package: usethis
R> install_github("treemap", username="mtennekes", subdir="pkg")
Error in parse_repo_spec(repo) :
Invalid git repo specification: 'treemap'
Error in collapse_cnd_message(message) :
could not find function "collapse_cnd_message"
> remotes::install_github("treemap", username = "mtennekes", subdir = "pkg")
Error in parse_repo_spec(repo) :
Invalid git repo specification: 'treemap'
R> remotes::install_github("mtennekes/treemap")
Using github PAT from envvar GITHUB_PAT
Downloading GitHub repo mtennekes/treemap@HEAD
Error: Failed to install 'treemap' from GitHub:
Does not appear to be an R package (no DESCRIPTION)
Hi...
I am wondering if treemap function can accept caption argument!
I am using R, Shiny, and Highcharter and I would like to click an Action Button and have the treemap drill down into a section that I designate. So for instance I click the "mybutton" action button and it drills down into the Europe section. I have tried three separate functions (jscode1, jscode2, jscode3), all of which do not work. is this possible with the current API? Reproducible code:
library("shiny")
library("highcharter")
library("shinyjs")
library("treemap")
library("viridisLite")
data(GNI2014)
jscode <- "shinyjs.drillDownFunction = function() {
var chart = $('#hcontainer').highcharts();
chart.series[0].data[0].firePointEvent('click');
console.log(chart);}"
jscode2 <- "shinyjs.drillDownFunction2 = function() {
var chart = $('#hcontainer').highcharts();
chart.series[0].data[0].series.hcEvents.click[0]();
console.log(chart);}"
jscode3 <- "shinyjs.drillDownFunction3 = function() {
var chart = $('#hcontainer').highcharts();
Highcharts.fireEvent(chart.series[0].data[0], 'click');
console.log(chart);}"
ui <-
fluidPage(
useShinyjs(),
extendShinyjs(text = jscode, functions = "drillDownFunction"),
extendShinyjs(text = jscode2, functions = "drillDownFunction2"),
extendShinyjs(text = jscode3, functions = "drillDownFunction3"),
fluidRow(
column(width = 8, highchartOutput("hcontainer"))),
fluidRow(
column(width = 4, textOutput("text"))),
fluidRow(
column(width = 4, actionButton("mybutton", "Drill Down into TreeMap"),
actionButton("mybutton2", "Drill Down into TreeMap"),
actionButton("mybutton3", "Drill Down into TreeMap")))
)
server <- function(input, output) {
tm <- treemap(GNI2014, index = c("continent", "iso3"),
vSize = "GNI", vColor = "population",
type = "value", palette = magma(12))
output$hcontainer <- renderHighchart({
hctreemap(tm, allowDrillToNode = TRUE, allowPointSelect = TRUE) %>%
hc_title(text = "Gross National Income World Data")
})
shinyjs::onclick("mybutton", {
js$drillDownFunction()
})
shinyjs::onclick("mybutton2", {
js$drillDownFunction2()
})
shinyjs::onclick("mybutton3", {
js$drillDownFunction3()
})
}
shinyApp(ui = ui, server = server)
Hi, I think there is a new version of world bank GNI2010 (GNI2014).
http://data.worldbank.org/data-catalog/GNI-per-capita-Atlas-and-PPP-table
This issue was said to be fixed in version 2.4-2. It is not. This is NOT related to issue #34.
There is a data.table warning message when using type = color. Reproducible example:
mtcars %>% head %>%
mutate(color = "red") %>%
treemap(index = "cyl", vSize = "cyl", vColor = "color", type = "color")
Warning message:
In [.data.table
(dtfDT, , :=
("c", fact), with = FALSE) :
with=FALSE ignored, it isn't needed when using :=. See ?':=' for examples.
The issue impairs the use of d3Tree with treemaps
Hi Martijn,
I have looked at treemap and its references, and I like the very simple strip approach in Bederson, Shneiderman and Wattenberg (2002), because it perfectly preserves order in a very linear way. I have written a function (strip
) that does the calculations, resolving the issue of getting very lean last strips by a quick and dirty check whether the last two strips should be merged. I have checked out its performance against pivotSize
and squarified
(simulated data, informal checks only). strip
seems to do quite well in terms of maximum and average aspect ratio.
I attach the function and functions for checking it out (strip_algorithm_for_treemap_GPLge2.zip); I tried to make the function yield the output that you need, but I don't know treemap well enough to be sure that it fits all treemap requirements; at least it seems to handle the plot's aspect ratio a little differently, but that should be a rescaling issue only. Feel free to use and modify as needed for incorporating this nice little algorithm into treemap.
Best, Ulrike
I am using treemap in a Shiny app using the following parameters:
type="dens"
algorithm="pivotSize"
sortID="-size"
The rectangles in the treemap are ordered by size from left to right with the biggest rectangles on the left. However, the legend is shown from right to left with the largest index values show on the right side of the scale. I would like to reverse the order of the legend so the scale aligns to the treemap.
I don't see any existing method for accomplishing this. Am I overlooking something?
No biggy, but in the install_github version of treemap, in the documentation it states that border.col defines font size. Did you want to make it like this:
-one colour, which specifies the colour for all aggregation levels
-vector of two colours, which specify the colours for 1) the highest and 2) the other aggregation levels
-vector of three numbers, which specify the colours for 1) the highest, 2) any in-between, and 3) the lowest aggregation level.
The thickness of the intersection lines cannot be customized according the cran documentation. I'd like to make them a bit thicker to really make sure that hierarchies are visible.
Any trick to modify the lines thickness?
I started working on an interactive version with the idea that it works seamlessly with the return treemap list
. It is minimal and sparse now, but I would love your input. Happy to eventually roll it into treemap
if you would like. All the code is https://github.com/timelyportfolio/d3treeR.
Thanks for such a great package.
would you consider a pull request that let the user control the legend format? eg pass through arguments to format
so it can have big.marks, etc. I could have a go but won't put the effort in if you've already thought it through and decided there's enough customisation and long argument lists already.
Giving an ordering preference through parameter sortID
is broken.
Commit d8817db breaks the behaviour
# create data set
set.seed(1234)
df <- data.frame(A=LETTERS[1:12],size=seq(12,1),sort=sample(12))
# install the last version with sortID respected and plot treemap
devtools::install_github("treemap", user="mtennekes", subdir="pkg",ref="5ca7c0b562e4a60bab111752210d6aba8995f55a")
library(treemap)
treemap(df,index="A",vSize="size",algorithm="pivotSize",sortID="sort")
# install the version which breaks sortID and plot treemap
devtools::install_github("treemap", user="mtennekes", subdir="pkg",ref="d8817db2805058f6a36db9f882790681961bc052")
library(treemap)
treemap(df,index="A",vSize="size",algorithm="pivotSize",sortID="sort")
I am trying to replicate the hover plot from the "treemap" library examples in the following shinyapp:
library(shiny)
library(treemap)
library(dplyr)
library(gridBase)
weights <- readRDS("/home/R projects/treemap1.rds")
### Handle cliks on a treemap
tmLocate <-
function(coor, tmSave) {
tm <- tmSave$tm
# retrieve selected rectangle
rectInd <- which(tm$x0 < coor[1] & (tm$x0 + tm$w) > coor[1] &
tm$y0 < coor[2] & (tm$y0 + tm$h) > coor[2])
return(tm[rectInd[1], ])
}
ui = fluidPage(pageWithSidebar(
headerPanel("Interactive treemap"),
sidebarPanel(
selectInput("prov", "Select province:", choices = unique(weights$Region)), width = 2
),
mainPanel(
plotOutput("plot", hover="hover", height = 700, width = 900),
tableOutput("record")
))
)
server = function(input, output){
sel1 <- reactive({
weights %>% filter(Region %in% input$prov)
})
getRecord <- reactive({
x <- input$hover$x
y <- input$hover$y
x <- (x - .tm$vpCoorX[1]) / (.tm$vpCoorX[2] - .tm$vpCoorX[1])
y <- (y - .tm$vpCoorY[1]) / (.tm$vpCoorY[2] - .tm$vpCoorY[1])
l <- tmLocate(list(x=x, y=y), .tm)
l[, 1:(ncol(l)-9)]
})
output$plot <- renderPlot({
#cat(input$hover$x, "\n")
par(mar=c(0,0,0,0), xaxs='i', yaxs='i')
plot(c(0,1), c(0,1),axes=F, col="white")
vps <- baseViewports()
.tm <<- treemap(sel1(),
index=c("Level.0","Level.1"),
vSize="X2015", vp=vps$plot)
})
output$record <- renderTable({
getRecord()
})
}
shinyApp(ui=ui, server=server)
Unfortunately, for some variables (like Shelter or Transportation) the hover treemap shows only the values only for the "Level.0" and for other variables it show the values for Level.1 how it should be.
I am trying to show only the values of Level.1 when hovering the treemap and I think that the issue is within the tmLocate function (or maybe the getRecord one) which I don't fully understand.
The dataset can be found here
Hi - does this support crosstalk?
There is a warning when executing the first example on examples/treemap.R :
data(GNI2014)
treemap(GNI2014,
index=c("continent", "iso3"),
vSize="population",
vColor="GNI",
type="value",
format.legend = list(scientific = FALSE, big.mark = " "))
# Warning message:
# In `[.data.table`(dtfDT, , `:=`(d, fact), with = FALSE) :
# with=FALSE together with := was deprecated in v1.9.4 released Oct 2014. Please wrap the LHS of := with parentheses; e.g., DT[,(myVar):=sum(b),by=a] to assign to column name(s) held in variable myVar. See ?':=' for other examples. As warned in 2014, this is now a warning.
Hi Martijn,
I find that the legend to treemap shows wrong labels under some circumstances, see the following code:
data("GNI2014")
GNI2014sort <- GNI2014
GNI2014sort$contnum <- as.numeric(GNI2014sort$continent)
## legend OK for the following call
treemap(GNI2014sort, "iso3", "population",
algorithm="pivotSize", vColor="contnum", type="value")
## legend not OK for the following call
treemap(GNI2014sort, "continent", "population",
algorithm="pivotSize", vColor="contnum", type="value")
In the second call, the labels shown are 20 times the actual values (which are 1 to 8). (Of course, this is a situation in which one would better suppress the legend altogether, but nevertheless the values shown should be correct.)
Best, Ulrike
Hi,
The following behaviour confused me a lot today (maybe just for future reference)
> library(dplyr)
> library(treemap)
> df <- data.frame(x=1:2, y=3:4, z=c("foo", "bar"))
> treemap(df, index="z", vSize="x", type="index") # all good!
> df <- df %>% rowwise %>% mutate(y = x+y) # for this example only
> df
Source: local data frame [2 x 3]
Groups: <by row>
x y z
1 1 4 foo
2 2 6 bar
> class(df)
[1] "rowwise_df" "tbl_df" "tbl" "data.frame"
> treemap(df, index="z", vSize="x", type="index")
Error in `:=`(vColor.temp, 1) :
Check that is.data.table(DT) == TRUE. Otherwise, := and `:=`(...) are defined for use in j, once only and in particular ways. See help(":=").
> ungroup(df) %>% treemap(index="z", vSize="x", type="index") # all good!
I don't suggest that treemap does the ungroup'ing, but I'd not have expected it to be that harmful ;)
Thanks for the great library :)
First of all thanks for an amazing package, I'm still exploring it and it's really great and comprehensively written.
I am however an R beginner, and have been trying to add a modification for enabling me to print out aggregate information (so sums, or percentages) below the labels. Do you have a suggestion of a starting point for me perhaps?
Cheers,
Maria
Hi
I am trying to embed itreemap function (interactive treemap) in R shiny. It keeps giving the error
"prod_metric_csv() is not a data.frame"
However, when I change the function to treemap, it works fine. It also works fine when I invoke the itreemap in regular rstudio (without shiny). Issue is occurring only when I embed in Shiny
Any pointers on the error is greatly appreciated.
Regards
Sunil
In treemap_2.1 the manual reads that the argument for changing the thickness of lines is lwds, but actually it is border.lwds.
Martijn,
the fix of commit 6a7f4b8 is needed now for being able to run treemap
with the affected color specifications (e.g. for bg
). Otherwise, an error (not a warning) is thrown, and no treemap is produced.
At the same time, the code for installing the development version does not run without changes, and it seems that the version number wasn't bumped (at least I had to uninstall the CRAN version for actually getting the development version installed).
It would be great if you could update the CRAN version in order to make it work with current R.
Best, Ulrike
Hi - is it possible to make the text clickable with an observe to open an url link , perhaps in the tooltip popup?
Hi M,
I seem unable to place my labels differently at different levels. For example, if I try:
data(business)
treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
type="index",
align.labels = c("right", "top", "left", "bottom"))
labels of both NACE1 and NACE2 are placed top right. The manual mentions to put arguments for multiple "as a list", but variations on the align.labels argument with "as.list()" did not prove useful.
Best,
Richard
Hi,
Trying to run
install.packages("treemap")
Results in :
Installing package into ‘/home/Etienne.Rolland/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
essai de l'URL 'https://cloud.r-project.org/src/contrib/treemap_2.4-3.tar.gz'
Content type 'application/x-gzip' length 133837 bytes (130 KB)
==================================================
downloaded 130 KB
* installing *source* package ‘treemap’ ...
** package ‘treemap’ correctement décompressé et sommes MD5 vérifiées
** using staged installation
** R
** data
** inst
** byte-compile and prepare package for lazy loading
Error in readRDS(nsInfoFilePath) : erreur de lecture de la connexion
Calls: <Anonymous> ... loadNamespace -> namespaceImport -> loadNamespace -> readRDS
Exécution arrêtée
ERROR: lazy loading failed for package ‘treemap’
* removing ‘/home/Etienne.Rolland/R/x86_64-pc-linux-gnu-library/3.6/treemap’
Warning in install.packages :
installation of package ‘treemap’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpSG9ax4/downloaded_packages’
I did some trace() to try to understand the error, but I did not find something meaningfull or related to only one broke dependencie.
Running :
devtools::install_github("treemap", username="mtennekes", subdir="pkg")
Results in :
Error in parse_repo_spec(repo) :
Invalid git repo specification: 'treemap'
I think, but I am unsure, that there is something broken with the installation process.
I am on R 3.6. Did not tried yet to reproduce on an other computer.
OS : [Ubuntu 20.04.4 LTS (Focal Fossa)]
First of all, thanks for the great package. I am currently using your code for one of my current articles, and I am wondering if its possible to include mathematical expressions and greek symbols in the plot. For instance if I use as a variable name expression(zeta[M]), nothing occurs and I cannot find a way to allow to parse the variables. Thanks a lot!!!
Version: 2.4 Check: whether package can be installed Result: WARN Found the following significant warnings: Warning: replacing previous import by ‘grid::arrow’ when loading ‘treemap’ Warning: replacing previous import by ‘grid::unit’ when loading ‘treemap’ Flavors: r-release-linux-x86_64, r-oldrel-windows-ix86+x86_64
I dislike argument bloat, but based on d3treeR/d3treeR#12 from d3treeR
, would it be possible to add an argument to skip the grid
drawing piece in lines. Using the contrived example from d3treeR/d3treeR#12 with 4000 rows, here is the lineprof
view.
I hesitate to even ask since treemap
was designed for output, but would it be possible to add an argument to skip the plotting for use with d3treeR
or other potential piggybacking packages?
Dear Martijn,
Do you plan to add the changes in commit #49 into CRAN?
Currently, strict build systems like the one used in Bioconductor will fail the checks for packages using the treemap
function as it is now in CRAN.
cheers,
Sergi
I'm sure this is my own ignorance, but it appears that colors in the aggregate work differently than I would expect. For instance, if we use only do one level using GNI2010
.
library(treemap)
library(dplyr)
treemap(GNI2010, index=c("continent"), vSize="GNI", vColor="GNI", type="value") %>%
{ .$tm } %>%
select( continent, vColor, color )
gives me
continent vColor color
1 Africa 106410 #EFF8AA
2 Asia 285410 #CEEA84
3 Europe 1056360 #0F8445
4 North America 240850 #D9EF8B
5 Oceania 80770 #F3FAAF
6 South America 71410 #F3FAAF
and
while setting index = c("continent","iso3")
gets me different colors.
treemap(GNI2010, index=c("continent","iso3"), vSize="GNI", vColor="GNI", type="value") %>%
{ .$tm } %>%
filter( is.na(iso3) ) %>%
select( continent, vColor, color )
gives me
continent vColor color
1 Africa 106410 #006837
2 Asia 285410 #006837
3 Europe 1056360 #006837
4 North America 240850 #006837
5 Oceania 80770 #0C7F43
6 South America 71410 #1A9850
and a ugly plot to show the colors
Naively, I would expect the colors assigned to the aggreage continent
to be the same. This is important when trying to match the colors assigned by treemap
in #17.
There is a data.table warning message when using type = color
. Reproducible example:
mtcars %>% head %>%
mutate(color = "red") %>%
treemap(index = "cyl", vSize = "cyl", vColor = "color", type = "color")
Warning message:
In `[.data.table`(dtfDT, , `:=`("c", fact), with = FALSE) :
with=FALSE ignored, it isn't needed when using :=. See ?':=' for examples.
The shiny.R test file reports:
Error in .func() : could not find function "tmLocate"
I installed the package using install_github
rather than from CRAN and the repo still includes a tmLocate.R definition and ls(getNamespace("treemap"), all.names=TRUE)
confirms the function is there.
Note: There's also a warning that hoverID
has been deprecated in shiny
and that hover
is now sufficient.
data("business")
treemap(business, index = c("NACE1", "NACE2"), vSize = "turnover", type = "index", fontsize.labels = c(15, 12))
treemap(business, index = c("NACE1", "NACE2"), vSize = "turnover", type = "index", fontsize.labels = c(12, 12))
treemap(business, index = c("NACE1", "NACE2"), vSize = "turnover", type = "index", fontsize.labels = c(0, 12))
Hi,
It's clearly stated in the documentation that the object to be used for the treemap should be a dataframe. Technically data.table's are dataframes, but they don't seem to work well with the treemap syntax, although from some errors it appears that treemap uses data.table internally (at least in the case of itreemap). While the obvious solution is of course to revert the data.table to a data.frame, it seems like a bug or hidden feature.
Code to illustrate this point (replace // with #):
data(GNI2010)
library(data.table)
// works:
treemap(GNI2010,
index=c("continent", "iso3"),
vSize="population",
vColor="GNI",
type="value")
// GNI2010 as data.table doesn't work:
GNI2010.dt <- data.table(GNI2010)
treemap(GNI2010.dt,
index=c("continent", "iso3"),
vSize="population",
vColor="GNI",
type="value")
// Error in setnames(dtfDT, old = names(dtfDT), new = c(indexList, "s", "c", :
// x is not a data.table or data.frame
// reverting back to data.frame works:
GNI2010.dt.df <- as.data.frame(GNI2010.dt)
treemap(GNI2010.dt.df,
index=c("continent", "iso3"),
vSize="population",
vColor="GNI",
type="value")
Hi, I was wondering whether it would be possible to use some kind of pattern fill for the leaves rather than colour. For example, by plotting symbols on the the leaves (or just using different line types). The purpose of this would be to have tree maps for black and white printing.
I saw in the presentation that a Javascript library was "in the near future". I would love to contribute if you have something started. Thanks for all your packages.
I would like the color palette in the following example to start in red instead of yellow
library(treemap)
data(business)
business$employees.growth <- business$employees - business$employees.prev + 15457
treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
vColor="employees.growth",
type="value",
palette="RdYlGn")
Is that possible?
Hi,
in the documentation there is small typo in the "align.labels" section:
"or a list of sush character vectors,"
such <- sush
Also it could be mentioned in the docs that one first has to specify horizontal alignment and then vertical alignment, not the other way around.
Best,
Richard
ps: I wouldn't mind to do so myself, but please let me know how.
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.