treemap package in r and examples
TRANSCRIPT
![Page 1: treemap package in R and examples](https://reader034.vdocuments.us/reader034/viewer/2022051300/5873628e1a28abe7648b5f4b/html5/thumbnails/1.jpg)
Prepared by Volkan OBAN
Treemap Examples in RTreemap Package.
Reference:https://cran.r-project.org/web/packages/treemap/treemap.pdf
![Page 2: treemap package in R and examples](https://reader034.vdocuments.us/reader034/viewer/2022051300/5873628e1a28abe7648b5f4b/html5/thumbnails/2.jpg)
1. > data(GNI2014)
> treemap(GNI2014,
index=c("continent", "iso3"),
vSize="population",
vColor="GNI",
type="value")
![Page 3: treemap package in R and examples](https://reader034.vdocuments.us/reader034/viewer/2022051300/5873628e1a28abe7648b5f4b/html5/thumbnails/3.jpg)
2- >data(business)
> treemap(business,
index=c("NACE1", "NACE2", "NACE3"),
vSize="turnover",
type="depth")
![Page 4: treemap package in R and examples](https://reader034.vdocuments.us/reader034/viewer/2022051300/5873628e1a28abe7648b5f4b/html5/thumbnails/4.jpg)
3- > business <- transform(business, data.available = factor(!is.na(turnover)), x = 1)
> treemap(business,
index=c("NACE1", "NACE2"),
vSize="x",
vColor="data.available",
type="categorical")
![Page 5: treemap package in R and examples](https://reader034.vdocuments.us/reader034/viewer/2022051300/5873628e1a28abe7648b5f4b/html5/thumbnails/5.jpg)
4- > business$color <- rainbow(nlevels(business$NACE2))[business$NACE2]
> treemap(business,
index=c("NACE1", "NACE2"),
vSize="x",
vColor="color",
type="color")
![Page 6: treemap package in R and examples](https://reader034.vdocuments.us/reader034/viewer/2022051300/5873628e1a28abe7648b5f4b/html5/thumbnails/6.jpg)
5- treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
fontsize.labels=c(12, 8),
align.labels=list(c("center", "center"), c("left", "top")),lowerbound.cex.labels=1)
![Page 7: treemap package in R and examples](https://reader034.vdocuments.us/reader034/viewer/2022051300/5873628e1a28abe7648b5f4b/html5/thumbnails/7.jpg)
6-treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
vColor="employees.growth",
type="value",
palette="-RdGy",
range=c(-20000,30000))
![Page 8: treemap package in R and examples](https://reader034.vdocuments.us/reader034/viewer/2022051300/5873628e1a28abe7648b5f4b/html5/thumbnails/8.jpg)
7-> treemap(business,
index=c("NACE1", "NACE2"),
vSize="employees",
vColor="employees.growth",
type="value",
palette="RdYlGn",
range=c(-20000,30000), # this is shown in the legend
mapping=c(-30000, 10000, 40000))
Reference:https://cran.r-project.org/web/packages/treemap/treemap.pdf