https://github.com/poisonalien/squarify
Minimal, zero dependancy package for drawing treemaps in R
https://github.com/poisonalien/squarify
rstats treemap treemap-diagram visulization
Last synced: about 1 year ago
JSON representation
Minimal, zero dependancy package for drawing treemaps in R
- Host: GitHub
- URL: https://github.com/poisonalien/squarify
- Owner: PoisonAlien
- License: other
- Created: 2023-08-16T13:15:28.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-16T12:41:01.000Z (over 2 years ago)
- Last Synced: 2025-02-05T16:48:46.784Z (over 1 year ago)
- Topics: rstats, treemap, treemap-diagram, visulization
- Language: R
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `squaRify`
`squaRify` is an R package for creating [treemaps](https://en.wikipedia.org/wiki/Treemapping) using base R. Treemaps are an effective way of visualizing hierarchical data by representing nested rectangles within larger rectangles. This package allows users to generate customizable treemaps to visually represent data structures efficiently.
## Features
- Base R Implementation: Utilizes native R functions to create treemaps without relying on any external libraries.
- Customizable: Users can modify colors, sizes, labels, and other visual aspects of the treemap.
- Hierarchical Visualization: Effectively displays hierarchical data through nested rectangles.
## Installation
You can install the package from GitHub using the `remotes` package:
```R
remotes::install_github(repo = "poisonalien/squaRify")
```
## Usage
```R
library(squaRify)
#example data (GDP of G7 countries - in trillions)
gdp = c(26.85, 4.41, 4.30, 3.15, 2.92, 2.17, 2.09)
gdp_countries = c("U.S.", "Japan", "Germany", "UK", "France", "Italy", "Canada")
squaRify::squarify(X = gdp, labels = gdp_countries)
```

### Customization
```R
#example data (GDP of G7 and BRICS countries - in trillions)
g7 = c(26.85, 4.41, 4.30, 3.15, 2.92, 2.17, 2.09)
g7_countries = c("U.S.", "Japan", "Germany", "UK", "France", "Italy", "Canada")
brics = c(19.37, 3.73, 2.08, 2.06, 0.39)
gbrics_countries = c("China", "India", "Brazil", "Russia", "SA")
par(mfrow = c(1, 2), mar = c(0, 0, 3, 0))
squaRify::squarify(
X = g7,
labels = g7_countries,
col = "#273c75",
alpha = 0.9,
text_col = "white",
borderCol = "white",
sub_labels = paste0(g7, "T"),
sub_text_col = "white",
text_font = 2
)
title(main = "G7 $45.89T total")
squarify::squarify(
X = brics,
labels = brics_countries,
col = "#c23616",
alpha = 0.9,
text_col = "white",
borderCol = "white",
sub_labels = paste0(brics, "T"),
sub_text_col = "white",
text_font = 2
)
title(main = "BRICS $27.63T total")
```

## Acknowledgements
The main algorithm is a direct translation of the [squarify](https://github.com/laserson/squarify) python package and, the main credit goes to [Uri Laserson](https://github.com/laserson).