diff --git a/DESCRIPTION b/DESCRIPTION index c3aa9d7..f427989 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: WeightedTreemaps Title: Generate and Plot Voronoi or Sunburst Treemaps from Hierarchical Data -Version: 0.1.1 +Version: 0.1.2 Authors@R: c( person("Michael", "Jahn", , "jahn@mpusp.mpg.de", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-3913-153X")), diff --git a/NEWS.md b/NEWS.md index d1cdedd..0ae50e7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ +# WeightedTreemaps 0.1.2 + # WeightedTreemaps 0.1.1 - The package was prepared for release on CRAN - A Shiny app for generating treemaps from custom data is now -available at [Shinyapps.io](https://m-jahn.shinyapps.io/ShinyTreemaps/) \ No newline at end of file +available at [Shinyapps.io](https://m-jahn.shinyapps.io/ShinyTreemaps/) diff --git a/R/drawTreemap.R b/R/drawTreemap.R index 02a4d8f..78e2d35 100644 --- a/R/drawTreemap.R +++ b/R/drawTreemap.R @@ -75,41 +75,44 @@ #' the input for the drawing function #' #' @examples -#' # load example data -#' data(mtcars) -#' mtcars$car_name = gsub(" ", "\n", row.names(mtcars)) +#' # load package +#' library(WeightedTreemaps) #' -#' # generate treemap; set seed to obtain same pattern every time +#' # generate dummy data +#' df <- data.frame( +#' A = rep(c("abcd", "efgh"), each = 4), +#' B = letters[1:8], +#' size = c(37, 52, 58, 27, 49, 44, 34, 45) +#' ) +#' +#' # compute treemap #' tm <- voronoiTreemap( -#' data = mtcars, -#' levels = c("gear", "car_name"), -#' cell_size = "wt", -#' shape = "rounded_rect", +#' data = df, +#' levels = c("B"), +#' cell_size = "size", +#' shape = "circle", +#' positioning = "regular", #' seed = 123 #' ) #' -#' # draw treemap -#' drawTreemap(tm, label_size = 2) +#' # plot treemap with each cell colored by name (default) +#' drawTreemap(tm, label_size = 1, color_type = "categorical") #' -#' # draw different variants of the same treemap on one page using -#' # the 'layout' and 'position' arguments (indicating rows and columns) -#' drawTreemap(tm, title = "treemap 1", label_size = 2, -#' color_type = "categorical", color_level = 1, -#' layout = c(1,3), position = c(1, 1)) +#' # plot treemap with each cell colored by name, but larger cells +#' # lighter and smaller cells darker +#' drawTreemap(tm, label_size = 1, color_type = "both") #' -#' drawTreemap(tm, title = "treemap 2", label_size = 2, -#' color_type = "categorical", color_level = 2, border_size = 3, -#' add = TRUE, layout = c(1,3), position = c(1, 2)) -#' -#' drawTreemap(tm, title = "treemap 3", label_size = 2, -#' color_type = "cell_size", color_level = 2, -#' color_palette = heat.colors(10), -#' border_color = grey(0.4), label_color = grey(0.4), -#' add = TRUE, layout = c(1,3), position = c(1, 3), -#' title_color = "black") +#' # plot treemap with different color palette and style +#' drawTreemap(tm, label_size = 1, label_color = grey(0.3), +#' border_color = grey(0.3), color_palette = heat.colors(6) +#' ) #' #' # --------------------------------------------- #' +#' # load example data +#' data(mtcars) +#' mtcars$car_name = gsub(" ", "\n", row.names(mtcars)) +#' #' # generate sunburst treemap #' tm <- sunburstTreemap( #' data = mtcars, diff --git a/R/voronoiTreemap.R b/R/voronoiTreemap.R index 6bb06a6..17507ca 100644 --- a/R/voronoiTreemap.R +++ b/R/voronoiTreemap.R @@ -81,38 +81,37 @@ #' @seealso \code{\link{drawTreemap}} for drawing the treemap. #' #' @examples -#' # load example data -#' data(mtcars) -#' mtcars$car_name = gsub(" ", "\n", row.names(mtcars)) +#' # load package +#' library(WeightedTreemaps) #' -#' # generate treemap; set seed to obtain same pattern every time +#' # generate dummy data +#' df <- data.frame( +#' A = rep(c("abcd", "efgh"), each = 4), +#' B = letters[1:8], +#' size = c(37, 52, 58, 27, 49, 44, 34, 45) +#' ) +#' +#' # compute treemap #' tm <- voronoiTreemap( -#' data = mtcars, -#' levels = c("gear", "car_name"), -#' cell_size = "wt", -#' shape = "rounded_rect", +#' data = df, +#' levels = c("B"), +#' cell_size = "size", +#' shape = "circle", +#' positioning = "regular", #' seed = 123 #' ) #' -#' # draw treemap -#' drawTreemap(tm, label_size = 2) +#' # plot treemap with each cell colored by name (default) +#' drawTreemap(tm, label_size = 1, color_type = "categorical") #' -#' # draw different variants of the same treemap on one page using -#' # the 'layout' and 'position' arguments (indicating rows and columns) -#' drawTreemap(tm, title = "treemap 1", label_size = 2, -#' color_type = "categorical", color_level = 1, -#' layout = c(1,3), position = c(1, 1)) +#' # plot treemap with each cell colored by name, but larger cells +#' # lighter and smaller cells darker +#' drawTreemap(tm, label_size = 1, color_type = "both") #' -#' drawTreemap(tm, title = "treemap 2", label_size = 2, -#' color_type = "categorical", color_level = 2, border_size = 3, -#' add = TRUE, layout = c(1,3), position = c(1, 2)) -#' -#' drawTreemap(tm, title = "treemap 3", label_size = 2, -#' color_type = "cell_size", color_level = 2, -#' color_palette = heat.colors(10), -#' border_color = grey(0.4), label_color = grey(0.4), -#' add = TRUE, layout = c(1,3), position = c(1, 3), -#' title_color = "black") +#' # plot treemap with different color palette and style +#' drawTreemap(tm, label_size = 1, label_color = grey(0.3), +#' border_color = grey(0.3), color_palette = heat.colors(6) +#' ) #' #' @importFrom Rcpp evalCpp #' @importFrom grid grid.newpage diff --git a/README.Rmd b/README.Rmd index 923fbfa..d1b3dfa 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,7 +1,7 @@ --- output: github_document title: "WeightedTreemaps" -author: "Michael Jahn, David Leslie, Ahmadou Dicko" +author: "Michael Jahn, David Leslie, Ahmadou Dicko, Paul Murrell" date: "`r Sys.Date()`" vignette: > %\VignetteIndexEntry{WeightedTreemaps} @@ -21,7 +21,8 @@ knitr::opts_chunk$set( -[![R build status](https://github.com/m-jahn/WeightedTreemaps/workflows/R-CMD-check/badge.svg)](https://github.com/m-jahn/WeightedTreemaps/actions) +[![CRAN status](https://www.r-pkg.org/badges/version/WeightedTreemaps)](https://CRAN.R-project.org/package=WeightedTreemaps) +[![R-CMD-check](https://github.com/m-jahn/WeightedTreemaps/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/m-jahn/WeightedTreemaps/actions/workflows/R-CMD-check.yaml) ![GitHub issues](https://img.shields.io/github/issues/m-jahn/WeightedTreemaps) ![GitHub last commit](https://img.shields.io/github/last-commit/m-jahn/WeightedTreemaps) ![Platform](https://img.shields.io/badge/platform-all-green) @@ -57,6 +58,12 @@ drawTreemap(tm, label_size = 2.5, label_color = "white", title = "An example") ## News +*14 December 2023* + +The package was finally released on CRAN! +Prerequisite was testing and troubleshooting of C++ related compilation problems, +and re-release of the CGAL dependency package `RcppCGAL` with latest version. + *25 March 2021* A **Shiny app** for generating treemaps from custom data is now available on **[Shinyapps.io](https://m-jahn.shinyapps.io/ShinyTreemaps/)!** @@ -76,11 +83,17 @@ The **Sunburst treemap** is a computationally less demanding treemap that does n The C++ code computing the actual Voronoi tesselation requires the [CGAL](https://www.cgal.org/download.html) library headers. Thanks to [Ahmadou Dicko](https://github.com/dickoa), installing the complete CGAL library locally is no longer necessary. Instead, the package depends on the CGAL headers that are available as R packages on CRAN. The package was using CGAL 4 (package `cgal4h`), but now moved to the latest CGAL 5.5+ version available as package `RcppCGAL`. The dependencies are usually installed automatically and manual installation of CGAL (headers) should not be necessary. -**NOTE**: The `RcppCGAL` package is currently (September 2023) not available on CRAN! Please install it [manually from Github](https://github.com/ericdunipace/RcppCGAL). +Note: If the `RcppCGAL` package is temporarily not available on CRAN (as happened 2023), please install it [manually from Github](https://github.com/ericdunipace/RcppCGAL). ## Installation -To install the package directly from github, use the following function from the `devtools` package in your R session: +To install the package from CRAN, use: + +```{r, eval = FALSE} +install.packages("WeightedTreemaps") +``` + +To install the package directly from github, use the following function from the `devtools` package: ```{r, eval = FALSE} devtools::install_github("m-jahn/WeightedTreemaps") diff --git a/README.md b/README.md index a1ce284..61e8ec7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ WeightedTreemaps ================ -Michael Jahn, David Leslie, Ahmadou Dicko -2023-12-12 +Michael Jahn, David Leslie, Ahmadou Dicko, Paul Murrell +2024-01-07 @@ -9,8 +9,9 @@ Michael Jahn, David Leslie, Ahmadou Dicko -[![R build -status](https://github.com/m-jahn/WeightedTreemaps/workflows/R-CMD-check/badge.svg)](https://github.com/m-jahn/WeightedTreemaps/actions) +[![CRAN +status](https://www.r-pkg.org/badges/version/WeightedTreemaps)](https://CRAN.R-project.org/package=WeightedTreemaps) +[![R-CMD-check](https://github.com/m-jahn/WeightedTreemaps/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/m-jahn/WeightedTreemaps/actions/workflows/R-CMD-check.yaml) ![GitHub issues](https://img.shields.io/github/issues/m-jahn/WeightedTreemaps) ![GitHub last @@ -28,6 +29,12 @@ hierarchical data. ## News +*14 December 2023* + +The package was finally released on CRAN! Prerequisite was testing and +troubleshooting of C++ related compilation problems, and re-release of +the CGAL dependency package `RcppCGAL` with latest version. + *25 March 2021* A **Shiny app** for generating treemaps from custom data is now @@ -83,14 +90,20 @@ was using CGAL 4 (package `cgal4h`), but now moved to the latest CGAL usually installed automatically and manual installation of CGAL (headers) should not be necessary. -**NOTE**: The `RcppCGAL` package is currently (September 2023) not -available on CRAN! Please install it [manually from +Note: If the `RcppCGAL` package is temporarily not available on CRAN (as +happened 2023), please install it [manually from Github](https://github.com/ericdunipace/RcppCGAL). ## Installation +To install the package from CRAN, use: + +``` r +install.packages("WeightedTreemaps") +``` + To install the package directly from github, use the following function -from the `devtools` package in your R session: +from the `devtools` package: ``` r devtools::install_github("m-jahn/WeightedTreemaps") @@ -135,7 +148,7 @@ Draw the treemap. drawTreemap(tm, label_size = 2.5, label_color = "white") ``` - + The `voronoiTreemap()` and `drawTreemap()` functions are separated in order to allow drawing of the same treemap object in different ways. @@ -170,7 +183,7 @@ drawTreemap(tm, title = "treemap 4", label_size = 2, title_color = "black", legend = TRUE) ``` - + ### Positioning of cells @@ -223,7 +236,7 @@ drawTreemap(tm3, title = "positioning = 'clustered'", border_size = 3, add = TRUE, layout = c(1,3), position = c(1, 3)) ``` - + ### Custom initial shapes @@ -271,7 +284,7 @@ drawTreemap(tm2, add = TRUE, layout = c(1,3), position = c(1, 2)) drawTreemap(tm3, add = TRUE, layout = c(1,3), position = c(1, 3)) ``` - + ### Advanced example for Voronoi treemaps @@ -546,7 +559,7 @@ drawTreemap(tm, ) ``` - + ## References and other treemap packages diff --git a/cran-comments.md b/cran-comments.md index d6549d9..e2f10e7 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,26 +1,4 @@ -## Resubmission - -This package was submitted previously, but returned with the following comments: - -1. "If there are references describing the methods in your package, please -add these in the description field of your DESCRIPTION file ..." - --> one reference was added to the DESCRIPTION. - -2. "Please add \value to .Rd files regarding exported methods and explain -the functions results in the documentation. Please write about the -structure of the output (class) ... Missing Rd-tags: poly_sortpoints.Rd: \value" - --> the documentation in \value fields was extended for several functions. -The function with a missing \value was removed. - -3. "You write information messages to the console that cannot be easily -suppressed. It is more R like to generate objects that can be used to extract the -information a user is interested in, and then print() that object. -Instead of print()/cat() rather use message()/warning() ..." - --> all cat() and print() statements were replaced by message(). Messages are -now only printed when the user specifies verbose = TRUE. +## Update ## Test environments @@ -32,33 +10,19 @@ now only printed when the user specifies verbose = TRUE. - ubuntu-latest (release) - ubuntu-latest (oldrel-1) - ### with `rhub::check_for_cran()` - Fedora Linux, R-devel, clang, gfortran - Debian Linux, R-release, GCC - Windows Server 2022, R-devel, 64 bit - Ubuntu Linux 20.04.1 LTS, R-release, GCC +- Debian Linux, R-devel, GCC ASAN/UBSAN ## R CMD check results There were no ERRORs or WARNINGs. -There were 2 NOTEs: - -1. Note: - -``` -File ‘WeightedTreemaps/libs/WeightedTreemaps.so’: - Found ‘__ZNSt3__14cerrE’, possibly from ‘std::cerr’ (C++) - Object: ‘voronoiDiagram.o’. Compiled code should not call entry - points which might terminate R nor write to stdout/stderr instead - of to the console, nor use Fortran I/O nor system RNGs. -``` - -The C++ function `voronoiDiagram.cpp` does not contain any such entry points. This Note occasionally turns up on Mac OS tests, probably caused by the upstream dependency CGAL headers (R package `RcppCGAL`) or boost headers (`BH`). - -2. Note: +There was 1 NOTE: ``` checking installed package size ... NOTE @@ -70,6 +34,9 @@ checking installed package size ... NOTE Installed package size exceeding 5 MB is caused by the compiled function `voronoiDiagram.o`. The size of this file can not be reduced. +There were "additional issues" brought up with from ASAN/UBSAN sanitizer checks. +These were fixed in the current version. + ## Downstream dependencies - There are currently no downstream dependencies for this package diff --git a/images/unnamed-chunk-9-1.png b/images/unnamed-chunk-10-1.png similarity index 100% rename from images/unnamed-chunk-9-1.png rename to images/unnamed-chunk-10-1.png diff --git a/images/unnamed-chunk-12-1.png b/images/unnamed-chunk-13-1.png similarity index 100% rename from images/unnamed-chunk-12-1.png rename to images/unnamed-chunk-13-1.png diff --git a/images/unnamed-chunk-22-1.png b/images/unnamed-chunk-23-1.png similarity index 100% rename from images/unnamed-chunk-22-1.png rename to images/unnamed-chunk-23-1.png diff --git a/images/unnamed-chunk-6-1.png b/images/unnamed-chunk-6-1.png deleted file mode 100644 index a8981e0..0000000 Binary files a/images/unnamed-chunk-6-1.png and /dev/null differ diff --git a/images/unnamed-chunk-7-1.png b/images/unnamed-chunk-7-1.png index 7df13a0..a8981e0 100644 Binary files a/images/unnamed-chunk-7-1.png and b/images/unnamed-chunk-7-1.png differ diff --git a/images/unnamed-chunk-8-1.png b/images/unnamed-chunk-8-1.png new file mode 100644 index 0000000..7df13a0 Binary files /dev/null and b/images/unnamed-chunk-8-1.png differ diff --git a/man/drawTreemap.Rd b/man/drawTreemap.Rd index 9f43f87..ea7ad9a 100644 --- a/man/drawTreemap.Rd +++ b/man/drawTreemap.Rd @@ -127,41 +127,44 @@ during treemap generation. Such parameters are primarily cell size and initial shape of the treemap. } \examples{ -# load example data -data(mtcars) -mtcars$car_name = gsub(" ", "\n", row.names(mtcars)) +# load package +library(WeightedTreemaps) + +# generate dummy data +df <- data.frame( + A = rep(c("abcd", "efgh"), each = 4), + B = letters[1:8], + size = c(37, 52, 58, 27, 49, 44, 34, 45) +) -# generate treemap; set seed to obtain same pattern every time +# compute treemap tm <- voronoiTreemap( - data = mtcars, - levels = c("gear", "car_name"), - cell_size = "wt", - shape = "rounded_rect", + data = df, + levels = c("B"), + cell_size = "size", + shape = "circle", + positioning = "regular", seed = 123 ) -# draw treemap -drawTreemap(tm, label_size = 2) - -# draw different variants of the same treemap on one page using -# the 'layout' and 'position' arguments (indicating rows and columns) -drawTreemap(tm, title = "treemap 1", label_size = 2, - color_type = "categorical", color_level = 1, - layout = c(1,3), position = c(1, 1)) +# plot treemap with each cell colored by name (default) +drawTreemap(tm, label_size = 1, color_type = "categorical") -drawTreemap(tm, title = "treemap 2", label_size = 2, - color_type = "categorical", color_level = 2, border_size = 3, - add = TRUE, layout = c(1,3), position = c(1, 2)) +# plot treemap with each cell colored by name, but larger cells +# lighter and smaller cells darker +drawTreemap(tm, label_size = 1, color_type = "both") -drawTreemap(tm, title = "treemap 3", label_size = 2, - color_type = "cell_size", color_level = 2, - color_palette = heat.colors(10), - border_color = grey(0.4), label_color = grey(0.4), - add = TRUE, layout = c(1,3), position = c(1, 3), - title_color = "black") +# plot treemap with different color palette and style +drawTreemap(tm, label_size = 1, label_color = grey(0.3), + border_color = grey(0.3), color_palette = heat.colors(6) +) # --------------------------------------------- +# load example data +data(mtcars) +mtcars$car_name = gsub(" ", "\n", row.names(mtcars)) + # generate sunburst treemap tm <- sunburstTreemap( data = mtcars, diff --git a/man/voronoiTreemap.Rd b/man/voronoiTreemap.Rd index 9aa79b6..c7e5a10 100644 --- a/man/voronoiTreemap.Rd +++ b/man/voronoiTreemap.Rd @@ -116,38 +116,37 @@ This function returns a treemap object instead of a plot. In order to actually draw the treemap, use \code{\link{drawTreemap}}. } \examples{ -# load example data -data(mtcars) -mtcars$car_name = gsub(" ", "\n", row.names(mtcars)) +# load package +library(WeightedTreemaps) + +# generate dummy data +df <- data.frame( + A = rep(c("abcd", "efgh"), each = 4), + B = letters[1:8], + size = c(37, 52, 58, 27, 49, 44, 34, 45) +) -# generate treemap; set seed to obtain same pattern every time +# compute treemap tm <- voronoiTreemap( - data = mtcars, - levels = c("gear", "car_name"), - cell_size = "wt", - shape = "rounded_rect", + data = df, + levels = c("B"), + cell_size = "size", + shape = "circle", + positioning = "regular", seed = 123 ) -# draw treemap -drawTreemap(tm, label_size = 2) - -# draw different variants of the same treemap on one page using -# the 'layout' and 'position' arguments (indicating rows and columns) -drawTreemap(tm, title = "treemap 1", label_size = 2, - color_type = "categorical", color_level = 1, - layout = c(1,3), position = c(1, 1)) - -drawTreemap(tm, title = "treemap 2", label_size = 2, - color_type = "categorical", color_level = 2, border_size = 3, - add = TRUE, layout = c(1,3), position = c(1, 2)) - -drawTreemap(tm, title = "treemap 3", label_size = 2, - color_type = "cell_size", color_level = 2, - color_palette = heat.colors(10), - border_color = grey(0.4), label_color = grey(0.4), - add = TRUE, layout = c(1,3), position = c(1, 3), - title_color = "black") +# plot treemap with each cell colored by name (default) +drawTreemap(tm, label_size = 1, color_type = "categorical") + +# plot treemap with each cell colored by name, but larger cells +# lighter and smaller cells darker +drawTreemap(tm, label_size = 1, color_type = "both") + +# plot treemap with different color palette and style +drawTreemap(tm, label_size = 1, label_color = grey(0.3), + border_color = grey(0.3), color_palette = heat.colors(6) +) } \seealso{ diff --git a/vignettes/WeightedTreemaps.R b/vignettes/WeightedTreemaps.R index 3d40e5e..3a6fd7a 100644 --- a/vignettes/WeightedTreemaps.R +++ b/vignettes/WeightedTreemaps.R @@ -15,74 +15,74 @@ library(WeightedTreemaps) data(mtcars) mtcars$car_name = gsub(" ", "\n", row.names(mtcars)) -## ----------------------------------------------------------------------------- -# generate treemap; set seed to obtain same pattern every time -tm <- voronoiTreemap( - data = mtcars, - levels = c("gear", "car_name"), - cell_size = "wt", - shape = "rounded_rect", - seed = 123 -) - -## ----fig.width = 5, fig.height = 5, out.width = "50%", fig.align = 'center'---- -drawTreemap(tm, label_size = 2.5, label_color = "white") - -## ----fig.width = 9, fig.height = 9, out.width = "100%", fig.align = 'center', warning = FALSE---- -drawTreemap(tm, title = "treemap 1", label_size = 2, - color_type = "categorical", color_level = 1, - layout = c(2, 2), position = c(1, 1), legend = TRUE) - -drawTreemap(tm, title = "treemap 2", label_size = 2, - color_type = "categorical", color_level = 2, border_size = 3, - add = TRUE, layout = c(2, 2), position = c(1, 2), legend = TRUE) - -drawTreemap(tm, title = "treemap 3", label_size = 2, - color_type = "both", color_level = 1, - add = TRUE, layout = c(2, 2), position = c(2, 1), legend = TRUE) - -drawTreemap(tm, title = "treemap 4", label_size = 2, - color_type = "cell_size", color_level = 2, - color_palette = heat.colors(10), - border_color = grey(0.4), label_color = grey(0.4), - add = TRUE, layout = c(2, 2), position = c(2, 2), - title_color = "black", legend = TRUE) - -## ----message = FALSE, error = FALSE, results = 'hide'------------------------- -# set seed to obtain same df every time -set.seed(123) -df <- data.frame(A = sample(10:100, 45)) - -tm1 <- voronoiTreemap( - data = df, levels = "A", - cell_size = "A", - shape = "rounded_rect", - positioning = "random" -) - -tm2 <- voronoiTreemap( - data = df, levels = "A", - cell_size = "A", - shape = "rounded_rect", - positioning = "regular" -) - -tm3 <- voronoiTreemap( - data = df, levels = "A", - cell_size = "A", - shape = "rounded_rect", - positioning = "clustered" -) - -## ----fig.width = 12, fig.height = 4, out.width = "100%", fig.align = 'center', warning = FALSE---- -drawTreemap(tm1, title = "positioning = 'random'", border_size = 3, - layout = c(1,3), position = c(1, 1)) - -drawTreemap(tm2, title = "positioning = 'regular'", border_size = 3, - add = TRUE, layout = c(1,3), position = c(1, 2)) - -drawTreemap(tm3, title = "positioning = 'clustered'", border_size = 3, - add = TRUE, layout = c(1,3), position = c(1, 3)) +## ----eval = FALSE------------------------------------------------------------- +# # generate treemap; set seed to obtain same pattern every time +# tm <- voronoiTreemap( +# data = mtcars, +# levels = c("gear", "car_name"), +# cell_size = "wt", +# shape = "rounded_rect", +# seed = 123 +# ) + +## ----fig.width = 5, fig.height = 5, out.width = "50%", fig.align = 'center', eval = FALSE---- +# drawTreemap(tm, label_size = 2.5, label_color = "white") + +## ----fig.width = 9, fig.height = 9, out.width = "100%", fig.align = 'center', warning = FALSE, eval = FALSE---- +# drawTreemap(tm, title = "treemap 1", label_size = 2, +# color_type = "categorical", color_level = 1, +# layout = c(2, 2), position = c(1, 1), legend = TRUE) +# +# drawTreemap(tm, title = "treemap 2", label_size = 2, +# color_type = "categorical", color_level = 2, border_size = 3, +# add = TRUE, layout = c(2, 2), position = c(1, 2), legend = TRUE) +# +# drawTreemap(tm, title = "treemap 3", label_size = 2, +# color_type = "both", color_level = 1, +# add = TRUE, layout = c(2, 2), position = c(2, 1), legend = TRUE) +# +# drawTreemap(tm, title = "treemap 4", label_size = 2, +# color_type = "cell_size", color_level = 2, +# color_palette = heat.colors(10), +# border_color = grey(0.4), label_color = grey(0.4), +# add = TRUE, layout = c(2, 2), position = c(2, 2), +# title_color = "black", legend = TRUE) + +## ----message = FALSE, error = FALSE, results = 'hide', eval = FALSE----------- +# # set seed to obtain same df every time +# set.seed(123) +# df <- data.frame(A = sample(10:100, 45)) +# +# tm1 <- voronoiTreemap( +# data = df, levels = "A", +# cell_size = "A", +# shape = "rounded_rect", +# positioning = "random" +# ) +# +# tm2 <- voronoiTreemap( +# data = df, levels = "A", +# cell_size = "A", +# shape = "rounded_rect", +# positioning = "regular" +# ) +# +# tm3 <- voronoiTreemap( +# data = df, levels = "A", +# cell_size = "A", +# shape = "rounded_rect", +# positioning = "clustered" +# ) + +## ----fig.width = 12, fig.height = 4, out.width = "100%", fig.align = 'center', warning = FALSE, eval = FALSE---- +# drawTreemap(tm1, title = "positioning = 'random'", border_size = 3, +# layout = c(1,3), position = c(1, 1)) +# +# drawTreemap(tm2, title = "positioning = 'regular'", border_size = 3, +# add = TRUE, layout = c(1,3), position = c(1, 2)) +# +# drawTreemap(tm3, title = "positioning = 'clustered'", border_size = 3, +# add = TRUE, layout = c(1,3), position = c(1, 3)) ## ----------------------------------------------------------------------------- # different initial shapes, the more squared the better @@ -99,20 +99,20 @@ oct_coord <- list( y = cos(seq(0, 2, 2/8)*pi) * 1000 + 1000 ) -## ----message = FALSE, error = FALSE, results = 'hide'------------------------- -tm1 <- voronoiTreemap(data = df, levels = "A", - shape = house_coords) - -tm2 <- voronoiTreemap(data = df, levels = "A", - shape = rect_coords) - -tm3 <- voronoiTreemap(data = df, levels = "A", - shape = oct_coord) - -## ----fig.width = 12, fig.height = 4, out.width = "100%", fig.align = 'center', warning = FALSE---- -drawTreemap(tm1, layout = c(1,3), position = c(1, 1)) -drawTreemap(tm2, add = TRUE, layout = c(1,3), position = c(1, 2)) -drawTreemap(tm3, add = TRUE, layout = c(1,3), position = c(1, 3)) +## ----message = FALSE, error = FALSE, results = 'hide', eval = FALSE----------- +# tm1 <- voronoiTreemap(data = df, levels = "A", +# shape = house_coords) +# +# tm2 <- voronoiTreemap(data = df, levels = "A", +# shape = rect_coords) +# +# tm3 <- voronoiTreemap(data = df, levels = "A", +# shape = oct_coord) + +## ----fig.width = 12, fig.height = 4, out.width = "100%", fig.align = 'center', warning = FALSE, eval = FALSE---- +# drawTreemap(tm1, layout = c(1,3), position = c(1, 1)) +# drawTreemap(tm2, add = TRUE, layout = c(1,3), position = c(1, 2)) +# drawTreemap(tm3, add = TRUE, layout = c(1,3), position = c(1, 3)) ## ----------------------------------------------------------------------------- # generate data frame diff --git a/vignettes/WeightedTreemaps.Rmd b/vignettes/WeightedTreemaps.Rmd index 35d2972..17e65f9 100644 --- a/vignettes/WeightedTreemaps.Rmd +++ b/vignettes/WeightedTreemaps.Rmd @@ -1,7 +1,7 @@ --- output: rmarkdown::html_vignette title: "WeightedTreemaps" -author: "Michael Jahn, David Leslie, Ahmadou Dicko" +author: "Michael Jahn, David Leslie, Ahmadou Dicko, Paul Murrell" date: "`r Sys.Date()`" vignette: > %\VignetteIndexEntry{WeightedTreemaps} @@ -65,7 +65,7 @@ Generate the treemap. It will return a list of polygons and metadata. The columns of the data frame that are used as levels of the treemap need to be specified. Different parameters like the initial shape, or the maximum number of iterations are optional. -```{r} +```{r, eval = FALSE} # generate treemap; set seed to obtain same pattern every time tm <- voronoiTreemap( data = mtcars, @@ -78,14 +78,15 @@ tm <- voronoiTreemap( Draw the treemap. -```{r, fig.width = 5, fig.height = 5, out.width = "50%", fig.align = 'center'} +```{r, fig.width = 5, fig.height = 5, out.width = "50%", fig.align = 'center', eval = FALSE} drawTreemap(tm, label_size = 2.5, label_color = "white") ``` + The `voronoiTreemap()` and `drawTreemap()` functions are separated in order to allow drawing of the same treemap object in different ways. Computation of treemaps with thousands of cells can be very time and resource consuming (around 5-10 minutes for a 2000-cell treemap on a regular desktop computer). With the `drawTreemap()` function, we can not only plot the same treemap in different ways but also combine several treemaps on one page using the `layout` and `position` arguments. The most important style element is color. Coloring can be based on cell category, cell size, or both, using the `color_type` argument. By default, the highest hierarchical level is used for coloring but that can be customized using the `color_level` argument. -```{r, fig.width = 9, fig.height = 9, out.width = "100%", fig.align = 'center', warning = FALSE} +```{r, fig.width = 9, fig.height = 9, out.width = "100%", fig.align = 'center', warning = FALSE, eval = FALSE} drawTreemap(tm, title = "treemap 1", label_size = 2, color_type = "categorical", color_level = 1, layout = c(2, 2), position = c(1, 1), legend = TRUE) @@ -106,12 +107,13 @@ drawTreemap(tm, title = "treemap 4", label_size = 2, title_color = "black", legend = TRUE) ``` + ### Positioning of cells Generating a Voronoi treemap is an iterative and somewhat random process. Since the cells 'move' during the iteration process, it can be difficult to control the exact final position of cells. However, there are two ways to influence cell positioning. The first is to use different algorithms for sampling initial coordinates for each cell. The second is simply setting a seed, which will sample the same set of starting coordinates for the same input data. Regarding the `positioning` argument, compare the following three examples where initial positions are 1) random, 2) ordered from top to bottom, or 3) ordered from center to edges. -```{r, message = FALSE, error = FALSE, results = 'hide'} +```{r, message = FALSE, error = FALSE, results = 'hide', eval = FALSE} # set seed to obtain same df every time set.seed(123) df <- data.frame(A = sample(10:100, 45)) @@ -139,7 +141,7 @@ tm3 <- voronoiTreemap( ``` -```{r, fig.width = 12, fig.height = 4, out.width = "100%", fig.align = 'center', warning = FALSE} +```{r, fig.width = 12, fig.height = 4, out.width = "100%", fig.align = 'center', warning = FALSE, eval = FALSE} drawTreemap(tm1, title = "positioning = 'random'", border_size = 3, layout = c(1,3), position = c(1, 1)) @@ -150,6 +152,8 @@ drawTreemap(tm3, title = "positioning = 'clustered'", border_size = 3, add = TRUE, layout = c(1,3), position = c(1, 3)) ``` + + ### Custom initial shapes Instead of using predefined shapes, we can also supply a custom set of coordinates to plot a treemap using the `shape` argument. The validity of the supplied coordinates is not checked, so all responsibility lies with the user (!). The R session might even crash (due to C++ dependency) if a shape is supplied that is too irregular or edgy, and the tesselation becomes unfeasible. Here are some stable examples. @@ -172,7 +176,7 @@ oct_coord <- list( Let's generate treemaps with the shapes of a house, a wide rectangle, and an octogon. -```{r, message = FALSE, error = FALSE, results = 'hide'} +```{r, message = FALSE, error = FALSE, results = 'hide', eval = FALSE} tm1 <- voronoiTreemap(data = df, levels = "A", shape = house_coords) @@ -184,12 +188,14 @@ tm3 <- voronoiTreemap(data = df, levels = "A", ``` -```{r, fig.width = 12, fig.height = 4, out.width = "100%", fig.align = 'center', warning = FALSE} +```{r, fig.width = 12, fig.height = 4, out.width = "100%", fig.align = 'center', warning = FALSE, eval = FALSE} drawTreemap(tm1, layout = c(1,3), position = c(1, 1)) drawTreemap(tm2, add = TRUE, layout = c(1,3), position = c(1, 2)) drawTreemap(tm3, add = TRUE, layout = c(1,3), position = c(1, 3)) ``` + + ### Sunburst treemaps Sunburst treemaps are generated in the same way as described above for Voronoi treemaps. diff --git a/vignettes/WeightedTreemaps.html b/vignettes/WeightedTreemaps.html index f080a37..3a8f785 100644 --- a/vignettes/WeightedTreemaps.html +++ b/vignettes/WeightedTreemaps.html @@ -10,9 +10,9 @@ - + - + WeightedTreemaps @@ -339,8 +339,9 @@

WeightedTreemaps

-

Michael Jahn, David Leslie, Ahmadou Dicko

-

2023-10-05

+

Michael Jahn, David Leslie, Ahmadou Dicko, Paul +Murrell

+

2024-01-07

@@ -430,7 +431,7 @@

Voronoi treemaps

)

Draw the treemap.

drawTreemap(tm, label_size = 2.5, label_color = "white")
-

+

The voronoiTreemap() and drawTreemap() functions are separated in order to allow drawing of the same treemap object in different ways. Computation of treemaps with thousands of @@ -462,7 +463,7 @@

Voronoi treemaps

border_color = grey(0.4), label_color = grey(0.4), add = TRUE, layout = c(2, 2), position = c(2, 2), title_color = "black", legend = TRUE) -

+

Positioning of cells

@@ -508,7 +509,7 @@

Positioning of cells

drawTreemap(tm3, title = "positioning = 'clustered'", border_size = 3, add = TRUE, layout = c(1,3), position = c(1, 3))
-

+

Custom initial shapes

@@ -545,7 +546,7 @@

Custom initial shapes

drawTreemap(tm1, layout = c(1,3), position = c(1, 1))
 drawTreemap(tm2, add = TRUE, layout = c(1,3), position = c(1, 2))
 drawTreemap(tm3, add = TRUE, layout = c(1,3), position = c(1, 3))
-

+

Sunburst treemaps