Skip to content

Commit 024693c

Browse files
author
Joseph Damiba
committed
wording fixups
1 parent 8a9eec9 commit 024693c

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

r/2020-02-25-treemap.Rmd

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ output:
1515
```{r, echo = FALSE, message=FALSE}
1616
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
1717
```
18-
[Treemap charts](https://en.wikipedia.org/wiki/Treemapping) visualize hierarchical data using nested rectangles. Same as [Sunburst](https://plot.ly/r/sunburst-charts/) the hierarchy is defined by [labels](https://plot.ly/r/reference/#treemap-labels), and [parents](https://plot.ly/r/reference/#treemap-parents) attributes. Click on one sector to zoom in/out, which also displays a pathbar in the upper-left corner of your treemap. To zoom out you can use the path bar as well.
18+
[Treemap charts](https://en.wikipedia.org/wiki/Treemapping) visualize hierarchical data using nested rectangles. Just like with a [sunburst chart](https://plot.ly/r/sunburst-charts/), the hierarchy of a treemap is defined by using the [labels](https://plot.ly/r/reference/#treemap-labels), and [parents](https://plot.ly/r/reference/#treemap-parents) attributes.
19+
20+
Treemaps created with Plotly's R graphing library are interactive by default! Click on individual sectors of the treemap chart to zoom in/out of that sector and to display a hierarchical pathbar at the top of the chart. You can use this pathbar to zoom in/out of chart sectors instead of clicking on the sectors directly.
1921

2022
### Basic Treemap
2123

@@ -29,16 +31,17 @@ fig <- plot_ly(
2931
)
3032
fig
3133
```
32-
### Set Different Attributes in Treemap
34+
### Customize Treemap Attributes
3335

34-
This example uses the following attributes:
36+
You can customize several attributes of the treemaps you create with Plotly for R, including:
3537

36-
1. [values](https://plot.ly/r/reference/#treemap-values): sets the values associated with each of the sectors.
37-
2. [textinfo](https://plot.ly/r/reference/#treemap-textinfo): determines which trace information appear on the graph that can be 'text', 'value', 'current path', 'percent root', 'percent entry', and 'percent parent', or any combination of them.
38-
3. [pathbar](https://plot.ly/r/reference/#treemap-pathbar): a main extra feature of treemap to display the current path of the visible portion of the hierarchical map. It may also be useful for zooming out of the graph.
39-
4. [branchvalues](https://plot.ly/r/reference/#treemap-branchvalues): determines how the items in `values` are summed. When set to "total", items in `values` are taken to be value of all its descendants. In the example below Eva = 65, which is equal to 14 + 12 + 10 + 2 + 6 + 6 + 1 + 4.
38+
1. [values](https://plot.ly/r/reference/#treemap-values): a list of the values assigned to each chart sector.
39+
2. [textinfo](https://plot.ly/r/reference/#treemap-textinfo): determines the textual information that will appear in each chart sector. Valid values are 'text', 'value', 'current path', 'percent root', 'percent entry', 'percent parent', or any combination of the preceding.
40+
3. [pathbar](https://plot.ly/r/reference/#treemap-pathbar): determines whether the pathbar is visible when users zoom into chart sectors.
41+
4. [branchvalues](https://plot.ly/r/reference/#treemap-branchvalues): the method that has been used to calculate the `values` of chart sectors that have desendants. Valid values for this attribute are `total` and `remainder`; the default value is `remainder`.
42+
- When set to `remainder`, items in the `values` attribute which correspond to the root of the chart and the branches sectors are taken to be the extra part not part of the sum of the values at their leaves.
43+
- When set to `total`, a brach's value is taken to be equal to the sum of the `values` of each chart sector that is a descendant of that branch. This behavior is demonstrated in the second trace in the example figure below- the value of the `Eva` branch is 65, which is the sum of the values of each chart sector that is a descendant of that branch (14 + 12 + 10 + 2 + 6 + 6 + 1 + 4).
4044

41-
When set to "remainder", items in `values` corresponding to the root and the branches sectors are taken to be the extra part not part of the sum of the values at their leaves.
4245

4346
```{r}
4447
library(plotly)
@@ -75,13 +78,13 @@ fig
7578

7679
### Set Color of Treemap Sectors
7780

78-
There are three different ways to change the color of the sectors in Treemap:
81+
There are three different attributes you can use to change the color of the sectors of treemaps you have created with Plotly for R:
7982

8083
1. [marker.colors](https://plot.ly/r/reference/#treemap-marker-colors),
81-
2. [colorway](https://plot.ly/r/reference/#treemap-colorway),
82-
3. [colorscale](https://plot.ly/r/reference/#treemap-colorscale).
84+
2. [marker.colorscale](https://plot.ly/r/reference/#treemap-colorscale).
85+
3. [colorway](https://plot.ly/r/reference/#treemap-colorway),
8386

84-
The following examples show how to use each of them.
87+
The following examples show how to use each attribute. To use `marker.colors`, pass a list of valid CSS colors or hexadecimal color codes.
8588

8689
```{r}
8790
library(plotly)
@@ -93,47 +96,50 @@ fig <- plot_ly(
9396
type="treemap",
9497
labels=labels,
9598
parents=parents,
96-
marker=list(colors=c("pink", "royalblue", "lightgray", "purple", "cyan", "lightgray", "lightblue")))
99+
marker=list(colors=c("#000", "royalblue", "lightgray", "purple", "#FFF", "lightgray", "lightblue")))
97100
fig
98101
```
99-
This example uses `treemapcolorway` attribute, which should be set in layout.
102+
The following example uses the `marker.colorsclae` attribute. Rather than using a list of colors, simply supply a colorscale. The built-in colorscales are:
103+
- `Greys`, `YlGnBu`, `Greens`, `YlOrRd`, `Bluered`, `RdBu`, `Reds`
104+
- `Blues`, `Picnic`, `Rainbow`, `Portland`, `Jet`, `Hot`
105+
- `Blackbody`, `Earth`, `Electric`, `Viridis`, `Cividis`
100106

101107
```{r}
102108
library(plotly)
103109
104110
labels = c("A1", "A2", "A3", "A4", "A5", "B1", "B2")
105111
parents = c("", "A1", "A2", "A3", "A4", "", "B1")
112+
values = c("11", "12", "13", "14", "15", "20", "30")
106113
107114
fig <- plot_ly(
108115
type="treemap",
109116
labels=labels,
110-
parents=parents)
117+
parents=parents,
118+
values=values,
119+
marker=list(colorscale='Reds'))
111120
112-
fig <- fig %>% layout(treemapcolorway=c("pink","lightgray"))
113121
fig
114122
```
115123

124+
The following example uses the `treemapcolorway` attribute, which should be set in the chart's layout.
125+
116126
```{r}
117127
library(plotly)
118128
119129
labels = c("A1", "A2", "A3", "A4", "A5", "B1", "B2")
120130
parents = c("", "A1", "A2", "A3", "A4", "", "B1")
121-
values = c("11", "12", "13", "14", "15", "20", "30")
122131
123132
fig <- plot_ly(
124133
type="treemap",
125134
labels=labels,
126-
parents=parents,
127-
values=values,
128-
marker=list(colorscale='Reds'))
135+
parents=parents)
129136
137+
fig <- fig %>% layout(treemapcolorway=c("pink","lightgray"))
130138
fig
131139
```
132-
133140
### Nested Layers in Treemap
134141

135-
The following example uses hierarchical data that includes layers and grouping. Treemap and [Sunburst](https://plot.ly/r/sunburst-charts/) charts reveal insights into the data, and the format of your hierarchical data. [maxdepth](https://plot.ly/r/reference/#treemap-maxdepth) attribute sets the number of rendered sectors from the given level.
136-
142+
The following example demonstrates how treemap charts can be used to reveal insights into the structure of hierarchical data that includes information about layers and grouping. The [maxdepth](https://plot.ly/r/reference/#treemap-maxdepth) attribute can be used to control how many levels of data are rendered; the default value of `-1` renders all the levels in the hierarchy.
137143
```{r}
138144
library(plotly)
139145
@@ -152,17 +158,16 @@ fig <- fig %>% add_trace(
152158
ids=df2$ids,
153159
labels=df2$labels,
154160
parents=df2$parents,
155-
maxdepth=3,
161+
maxdepth=1,
156162
domain=list(column=1))
157163
fig <- fig %>% layout(grid=list(columns=2, rows=1))
158164
fig
159165
160166
161167
```
168+
### Controlling Text Font Size with `uniformtext`
162169

163-
### Controlling text fontsize with uniformtext
164-
165-
If you want all the text labels to have the same size, you can use the `uniformtext` layout parameter. The `minsize` attribute sets the font size, and the `mode` attribute sets what happens for labels which cannot fit with the desired fontsize: either `hide` them or `show` them with overflow.
170+
By default, the font size of text labels in your treemap chart will vary to fit into the available space within a sector. However, if you want all the text labels in your treemap chart to have the same font size, you can use the `uniformtext` layout parameter. The `minsize` attribute sets the font size, and the `mode` attribute sets what happens to labels which cannot fit within a sector with the specified fontsize: either `hide` them or `show` them with overflow.
166171

167172
```{r}
168173
library(plotly)

0 commit comments

Comments
 (0)