hammock-plot 0.3__tar.gz → 1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Tiancheng Yang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,272 @@
1
+ Metadata-Version: 2.1
2
+ Name: hammock_plot
3
+ Version: 1.0
4
+ Summary: Hammock - visualization of categorical or mixed categorical/continuous data
5
+ Home-page: https://github.com/TianchengY/hammock_plot
6
+ Author: Tiancheng Yang
7
+ Author-email: t77yang@uwaterloo.ca
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Intended Audience :: Science/Research
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+
16
+ # Hammock plot
17
+
18
+
19
+ ## Description
20
+
21
+ The hammock plot draws a graph to visualize categorical or mixed categorical / continuous data.
22
+ Variables are lined up parallel to the vertical axis. Categories within a variable are spread out along a
23
+ vertical line. Categories of adjacent variables are connected by boxes. (The boxes are parallelograms; we
24
+ use boxes for brevity). The "width" of a box is proportional to the number of observations that correspond
25
+ to that box (i.e. have the same values/categories for the two variables). The "width" of a box refers to the
26
+ distance between the longer set of parallel lines rather than the vertical distance.
27
+
28
+ If the boxes degenerate to a single line, and no labels or missing values are used the hammock plot
29
+ corresponds to a parallel coordinate plot. Boxes degenerate into a single line if barwidth is so small that
30
+ the boxes for categorical variables appear to be a single line. For continuous variables boxes will usually
31
+ appear to be a single line because each category typically only contains one observation.
32
+
33
+ The order of variables in varlist determines the order of variables in the graph. All variables in varlist
34
+ must be numerical. String variables should be converted to numerical variables first, e.g. using encode or
35
+ destring.
36
+
37
+
38
+
39
+
40
+ ## Getting started
41
+
42
+ You can install hammock from `pip`:
43
+
44
+ ```shell
45
+ pip install hammock_plot
46
+ ```
47
+
48
+
49
+ ### Example: Asthma data
50
+
51
+ We import the diabetes dataset:
52
+
53
+ ```python
54
+ import hammock_plot
55
+ import pandas as pd
56
+ df = pd.read_csv('./data/data_asthma.csv')
57
+ ```
58
+
59
+ Minimal example of a hammock plot:
60
+ ```python
61
+ var = ["hospitalizations","group","gender","comorbidities"]
62
+ hammock = hammock_plot.Hammock(data_df = df)
63
+ ax = hammock.plot(var=var)
64
+ ```
65
+ <img src="image/asthma_minimal.png" alt="Minimal example for a Hammock plot" width="600"/>
66
+
67
+ The labels for the numerical variables aren't as desired; we would like the labels directly drawn on the data. We specify that we want no levels for our numerical variables.
68
+
69
+ ```python
70
+ numeric_levels = {"comorbidities": None, "hospitalizations": None}
71
+ ax = hammock.plot(var=var, numerical_var_levels=numeric_levels)
72
+ ```
73
+
74
+ <img src="image/asthma_levels.png" alt="Hammock plot" width="600"/>
75
+
76
+ The ordering of the child-adolescent-adult variable is not in the desired order; adult should not be in the middle. We now specify a specific order, child-adolescent-adult.
77
+
78
+ ```python
79
+ group_order = ["child", "adolescent", "adult"]
80
+ value_order = {"group": group_order}
81
+ hammock = hammock_plot.Hammock(data_df = df)
82
+ ax = hammock.plot(var=var, value_order=value_order, numerical_var_levels=numeric_levels)
83
+ ```
84
+
85
+ <!--- to restrict image size, I am using a an html command, rather than the standard ![](image.png) --->
86
+ <!--- ![Hammock plot ](image/asthma1.png) --->
87
+ <img src="image/asthma_value_order.png" alt="Hammock plot" width="600"/>
88
+
89
+ We highlight observations with comorbidities=0 in red:
90
+
91
+ ```python
92
+ ax = hammock.plot(var=var ,hi_var="comorbidities", hi_value=[0], colors=["red"], numerical_var_levels=numeric_levels)
93
+ ```
94
+
95
+ <!--- ![Hammock plot with highlighting](image/asthma_highlighting.png) --->
96
+ <img src="image/asthma_highlighting.png" alt="Hammock plot with highlighting" width="600"/>
97
+
98
+
99
+ ### Example Satisfaction scales for the diabetes data
100
+
101
+ We import the diabetes dataset:
102
+
103
+ ```python
104
+ import hammock_plot
105
+ import pandas as pd
106
+ df = pd.read_csv('./data/data_diabetes.csv')
107
+ ```
108
+
109
+ The three variables represent different ordinal scales for satisfaction. We are checking for missing values:
110
+ ```python
111
+ var = ["sataces","satcomm","satrate"]
112
+ hammock = hammock_plot.Hammock(data_df = df)
113
+ ax = hammock.plot(var=var, missing=True, min_bar_height=0.2,numerical_var_levels={"sataces": None, "satcomm": None, "satrate": None})
114
+ ```
115
+
116
+ <img src="image/diabetes.png" alt="Hammock plot for the Diabetes Data" width="600"/>
117
+
118
+ The missing value category is shown at the bottom for each variable. We find missing values for all 3 variables, but fewest for the last one. We also see a phenomenon called "top coding", where
119
+ satisfied respondents simply choose the highest value.
120
+
121
+ ### Example value_order for the Shakespeare data
122
+
123
+ We import the Shakespeare dataset:
124
+
125
+ ```python
126
+ import hammock_plot
127
+ import pandas as pd
128
+ df = pd.read_csv('./data/data_shakespeare.csv')
129
+ ```
130
+
131
+ We use `speaker_dict` to map the values of the variables `speaker1` and `speaker2` according to the social class hierarchy.
132
+ ```python
133
+ var_lst = ["type","speaker1","speaker2","sex1"]
134
+ color_lst = ["red","yellow","green"]
135
+ hi_value = ["Beggars","Citizens","Gentry"]
136
+
137
+ speaker_order=["Beggars", "Royalty", "Nobility", "Gentry", "Citizens", "Yeomanry"]
138
+
139
+ hammock = hammock_plot.Hammock(data_df = df)
140
+ ax = hammock.plot(var=var_lst,hi_var = "speaker1", hi_value=hi_value,color=color_lst, bar_width=0.6,missing=True,
141
+ value_order ={"speaker1":speaker_order,"speaker2":speaker_order} )
142
+ ```
143
+
144
+ <img src="image/shakespeare_order.png" alt="Hammock plot for the Shakespeare data, with value_order specified" width="600"/>
145
+
146
+ ### Example same_scale using Shakespeare data
147
+ We can accomplish similar results using `same_scale`.
148
+ ```python
149
+ hammock = hammock_plot.Hammock(data_df = df)
150
+ ax = hammock.plot(var=var_lst,hi_var = "speaker1", hi_value=hi_value,color=color_lst, bar_width=0.6,missing=True,
151
+ value_order ={"speaker1":speaker_order}, same_scale=["speaker1", "speaker2"] )
152
+ ```
153
+ <img src="image/shakespeare_scale.png" alt="Hammock plot for the Shakespeare data, with same_scale specified" width="600"/>
154
+
155
+ ### Example numerical_display_type using penguin data
156
+
157
+ We import the Shakespeare dataset:
158
+
159
+ ```python
160
+ import hammock_plot
161
+ import pandas as pd
162
+ df = pd.read_csv('./data/data_penguins.csv')
163
+ ```
164
+
165
+ We use `numerical_display_type` to control how we want to display our numerical data.
166
+
167
+ ```python
168
+ hammock = hammock_plot.Hammock(df)
169
+ ax = hammock.plot(
170
+ var= ["species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"],
171
+ hi_var="island",
172
+ hi_value=["Torgersen"],
173
+ missing=True,
174
+ numerical_display_type={"bill_length_mm":"box", "bill_depth_mm": "rugplot", "flipper_length_mm": "violin", "body_mass_g":"box"},
175
+ )
176
+ ```
177
+ <img src="image/penguin_display_violin.png" alt="Hammock plot for the penguin data, demonstrating numerical_display_type" width="600"/>
178
+
179
+ Box plots support multiple highlight values. Violin plots only support one highlight value.
180
+ ```python
181
+ ax = hammock.plot(
182
+ var= ["species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"],
183
+ hi_var="island",
184
+ hi_value=["Torgersen", "Biscoe"],
185
+ missing=True,
186
+ numerical_display_type={"bill_length_mm":"box", "bill_depth_mm": "box", "flipper_length_mm": "box", "body_mass_g":"box"},
187
+ )
188
+ ```
189
+ <img src="image/penguin_display_types.png" alt="Hammock plot for the penguin data, demonstrating numerical_display_type with multiple highlighting" width="600"/>
190
+
191
+ ## API Reference
192
+
193
+ ```
194
+ hammock()
195
+ ```
196
+
197
+ | Category | Parameter | Type | Description |
198
+ | --- | :-------- | :------- | :------------------------- |
199
+ | General | `var` | `List[str]` | List of variables to display. |
200
+ | | `value_order` | `Dict[str, List[int]]` | If specified, the order of the values in the plot follows the order of values in the list supplied in the dictionary. Only applicable to categorical variables |
201
+ | | `numerical_var_levels` | `Dict[str, int \| None]` | Specifies the number of subdivisions in the y-axis for numerical variables. Example: {"NumericalVarname": 9, "NumericalVarname2": None}. Default is 7. |
202
+ | | `numerical_display_type` | `Dict[str, str]` | Specifies the type of plot (rugplot, box plot, violin plot) for numerical variable display. Example: {"NumericalVarname": "rugplot", "NumericalVarname2": "violin", "NumericalVarname3": "box"}. Default is "rugplot". |
203
+ | | `missing` | `bool` | Whether or not to add a category for missing values at the bottom of the plot. If False, observations that have a missing value for any variable in the data frame (even those not used in the hammock plot) are removed. Default is False. |
204
+ | | `label` | `bool` | Whether or not to display labels between the plotting segments |
205
+ | | `unibar`| `bool` | Whether or not to display unibars between the plotting segments |
206
+ | Highlighting | `hi_var` | `str` | Variable to be highlighted. Default is none. |
207
+ | | `hi_value` | `List[str or int] or str or int` | Value(s) of `hi_var` to be highlighted. You can highlighted one or multiple values. You can also pass an expression (e.g. "x>1 and (x>5 or x<4)") in string when you want to specify a range for a numeric hi_var.|
208
+ | | `hi_box` | `str` | Controls how highlighted values are displayed within category labels. Options are "vertical" for vertically stacked color segments or "horizontal" for horizontally split color segments. Default is "vertical".|
209
+ | | `hi_missing` | `bool` | Whether or not missing values for `hi_var` should be highlighted. |
210
+ | | `color` | `List[str]` | List of colors corresponding to the list of values to be highlighted. Each color can be specified as a plain color name (e.g., `"red"`, `"yellow"`) or in the format `"color=alpha"` (e.g., `"red=0.5"`) to control transparency/intensity, where `alpha` is a decimal between 0 and 1. The default highlight color list is `["red", "green", "yellow", "lightblue", "orange", "gray", "brown", "olive", "pink", "cyan", "magenta"]`. |
211
+ | | `default_color` | `str` | Default color of plotting elements for boxes that are not highlighted. Default is "blue" |
212
+ | Manipulating Spacing and Layout | `uni_fraction` | `float` | Fraction of vertical space that should be populated by data. Adjusts the height of the data points. Defaults is 0.08. |
213
+ | | `space` | `float` |Fraction of horizontal space allocated to labels/univ. bars rather than to connecting boxes. Default is 0.3 |
214
+ | | `label_options` | `Dict[str, Dict[str, Any]]` | Manipulates the size and look of the labels. Args following the options in the website: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.text.html Example:{"ExampleVarname":{"fontsize":12,"fontstyle":"italic","fontweight":"black","color":"b"}} Default is None. |
215
+ | | `height` | `float` | Height of the plot in inches. Default is 10. |
216
+ | | `width` | `float` | Width of the plot in inches. Default is 15. Caution: Width too narrow may distort the plot. |
217
+ | | `alpha` | `float` | Alpha value for the colours in the plot. Float from 0-1. Default is 0.7. |
218
+ | | `min_bar_height` | `float` | Minimal bar height. Bars representing only a tiny fraction of the data may be so narrow, that they are invivisible in a plot. The default value tries to ensure this does not happen. Default is 0.1.
219
+ | Other options | `shape` | `str` | Shape of the boxes. "rectangle" (default) or "parallelogram". |
220
+ | | `same_scale` | `List[str]` | List of variables that have the same scale. Default is None. |
221
+ | | `display_figure` | `bool` | Whether or not to display the figure. This can be useful if you just want to save the plots. Default is 'True'. |
222
+ | | `save_path` | `str` | If it is not None, the figure will be saved to the given path with given name and format. Default is None. |
223
+
224
+
225
+ ## Historical context
226
+
227
+ In 1898, Sankey diagrams were developed to visualize flows of energy and materials.
228
+
229
+ In 1985, Inselberg popularized parallel coordinates to visualize continuous variables only. The central contribution is the use of parallel axes.
230
+
231
+ In 2003, Schonlau proposed the hammock plot. This was the first plot to visualize categorical data (or mixed categorical continuous data) on parallel axes.
232
+
233
+ In 2010, Rosvall proposed alluvial plots to visualize network variables over time. Rather than using bars to connect axes, alluvial plots use rounded curves. Alluvial plots are now also used to visualize categorical data.
234
+
235
+ There are several additional variations that also visualize categorical data including Parallel Set plots (Bendix et al, 2005), Right Angle plots (Hofmann and Vendettuoli, 2013),
236
+ and generalized parallel coordinate plots (GPCPs) (popularized by VanderPlas et al., 2023).
237
+
238
+ ### References
239
+ Bendix, F., Kosara, R., & Hauser, H. (2005). Parallel sets: visual analysis of categorical data. In IEEE Symposium on Information Visualization, 2005. INFOVIS 2005. 133-140.
240
+
241
+ Hofmann, H., & Vendettuoli, M. (2013). Common angle plots as perception-true visualizations of categorical associations. IEEE transactions on visualization and computer graphics, 19(12), 2297-2305.
242
+
243
+ Inselberg, A., & Dimsdale, B. (2009). Parallel coordinates. Human-Machine Interactive Systems, 199-233.
244
+
245
+ Rosvall, Martin, & Bergstrom, C.T. (2010) "Mapping change in large networks." PloS one 5.1: e8694.
246
+
247
+ Sankey, H. (1898). Introductory note on the thermal efficiency of steam-engines. report of
248
+ the committee appointed on the 31st march, 1896, to consider and report to the council
249
+ upon the subject of the definition of a standard or standards of thermal efficiency for
250
+ steam-engines: With an introductory note. In Minutes of proceedings of the institution
251
+ of civil engineers, Volume 134, pp. 278–283.
252
+
253
+ Schonlau M.
254
+ *[Visualizing Categorical Data Arising in the Health Sciences Using Hammock Plots.](http://www.schonlau.net/publication/03jsm_hammockplot.pdf)*
255
+ In Proceedings of the Section on Statistical Graphics, American Statistical Association; 2003
256
+
257
+ VanderPlas, S., Ge, Y., Unwin, A., & Hofmann, H. (2023).
258
+ Penguins Go Parallel: a grammar of graphics framework for generalized parallel coordinate plots.
259
+ Journal of Computational and Graphical Statistics, 1-16. (online first)
260
+
261
+ ### Other implementations of the hammock plot
262
+ There is also a Stata implementation `hammock` (available from the Stata archive SSC) and an R implementation as part of the package `ggparallel`.
263
+
264
+ [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)
265
+
266
+
267
+
268
+ ## Authors
269
+
270
+ - Tiancheng Yang t77yang@uwaterloo.ca
271
+
272
+
@@ -0,0 +1,257 @@
1
+ # Hammock plot
2
+
3
+
4
+ ## Description
5
+
6
+ The hammock plot draws a graph to visualize categorical or mixed categorical / continuous data.
7
+ Variables are lined up parallel to the vertical axis. Categories within a variable are spread out along a
8
+ vertical line. Categories of adjacent variables are connected by boxes. (The boxes are parallelograms; we
9
+ use boxes for brevity). The "width" of a box is proportional to the number of observations that correspond
10
+ to that box (i.e. have the same values/categories for the two variables). The "width" of a box refers to the
11
+ distance between the longer set of parallel lines rather than the vertical distance.
12
+
13
+ If the boxes degenerate to a single line, and no labels or missing values are used the hammock plot
14
+ corresponds to a parallel coordinate plot. Boxes degenerate into a single line if barwidth is so small that
15
+ the boxes for categorical variables appear to be a single line. For continuous variables boxes will usually
16
+ appear to be a single line because each category typically only contains one observation.
17
+
18
+ The order of variables in varlist determines the order of variables in the graph. All variables in varlist
19
+ must be numerical. String variables should be converted to numerical variables first, e.g. using encode or
20
+ destring.
21
+
22
+
23
+
24
+
25
+ ## Getting started
26
+
27
+ You can install hammock from `pip`:
28
+
29
+ ```shell
30
+ pip install hammock_plot
31
+ ```
32
+
33
+
34
+ ### Example: Asthma data
35
+
36
+ We import the diabetes dataset:
37
+
38
+ ```python
39
+ import hammock_plot
40
+ import pandas as pd
41
+ df = pd.read_csv('./data/data_asthma.csv')
42
+ ```
43
+
44
+ Minimal example of a hammock plot:
45
+ ```python
46
+ var = ["hospitalizations","group","gender","comorbidities"]
47
+ hammock = hammock_plot.Hammock(data_df = df)
48
+ ax = hammock.plot(var=var)
49
+ ```
50
+ <img src="image/asthma_minimal.png" alt="Minimal example for a Hammock plot" width="600"/>
51
+
52
+ The labels for the numerical variables aren't as desired; we would like the labels directly drawn on the data. We specify that we want no levels for our numerical variables.
53
+
54
+ ```python
55
+ numeric_levels = {"comorbidities": None, "hospitalizations": None}
56
+ ax = hammock.plot(var=var, numerical_var_levels=numeric_levels)
57
+ ```
58
+
59
+ <img src="image/asthma_levels.png" alt="Hammock plot" width="600"/>
60
+
61
+ The ordering of the child-adolescent-adult variable is not in the desired order; adult should not be in the middle. We now specify a specific order, child-adolescent-adult.
62
+
63
+ ```python
64
+ group_order = ["child", "adolescent", "adult"]
65
+ value_order = {"group": group_order}
66
+ hammock = hammock_plot.Hammock(data_df = df)
67
+ ax = hammock.plot(var=var, value_order=value_order, numerical_var_levels=numeric_levels)
68
+ ```
69
+
70
+ <!--- to restrict image size, I am using a an html command, rather than the standard ![](image.png) --->
71
+ <!--- ![Hammock plot ](image/asthma1.png) --->
72
+ <img src="image/asthma_value_order.png" alt="Hammock plot" width="600"/>
73
+
74
+ We highlight observations with comorbidities=0 in red:
75
+
76
+ ```python
77
+ ax = hammock.plot(var=var ,hi_var="comorbidities", hi_value=[0], colors=["red"], numerical_var_levels=numeric_levels)
78
+ ```
79
+
80
+ <!--- ![Hammock plot with highlighting](image/asthma_highlighting.png) --->
81
+ <img src="image/asthma_highlighting.png" alt="Hammock plot with highlighting" width="600"/>
82
+
83
+
84
+ ### Example Satisfaction scales for the diabetes data
85
+
86
+ We import the diabetes dataset:
87
+
88
+ ```python
89
+ import hammock_plot
90
+ import pandas as pd
91
+ df = pd.read_csv('./data/data_diabetes.csv')
92
+ ```
93
+
94
+ The three variables represent different ordinal scales for satisfaction. We are checking for missing values:
95
+ ```python
96
+ var = ["sataces","satcomm","satrate"]
97
+ hammock = hammock_plot.Hammock(data_df = df)
98
+ ax = hammock.plot(var=var, missing=True, min_bar_height=0.2,numerical_var_levels={"sataces": None, "satcomm": None, "satrate": None})
99
+ ```
100
+
101
+ <img src="image/diabetes.png" alt="Hammock plot for the Diabetes Data" width="600"/>
102
+
103
+ The missing value category is shown at the bottom for each variable. We find missing values for all 3 variables, but fewest for the last one. We also see a phenomenon called "top coding", where
104
+ satisfied respondents simply choose the highest value.
105
+
106
+ ### Example value_order for the Shakespeare data
107
+
108
+ We import the Shakespeare dataset:
109
+
110
+ ```python
111
+ import hammock_plot
112
+ import pandas as pd
113
+ df = pd.read_csv('./data/data_shakespeare.csv')
114
+ ```
115
+
116
+ We use `speaker_dict` to map the values of the variables `speaker1` and `speaker2` according to the social class hierarchy.
117
+ ```python
118
+ var_lst = ["type","speaker1","speaker2","sex1"]
119
+ color_lst = ["red","yellow","green"]
120
+ hi_value = ["Beggars","Citizens","Gentry"]
121
+
122
+ speaker_order=["Beggars", "Royalty", "Nobility", "Gentry", "Citizens", "Yeomanry"]
123
+
124
+ hammock = hammock_plot.Hammock(data_df = df)
125
+ ax = hammock.plot(var=var_lst,hi_var = "speaker1", hi_value=hi_value,color=color_lst, bar_width=0.6,missing=True,
126
+ value_order ={"speaker1":speaker_order,"speaker2":speaker_order} )
127
+ ```
128
+
129
+ <img src="image/shakespeare_order.png" alt="Hammock plot for the Shakespeare data, with value_order specified" width="600"/>
130
+
131
+ ### Example same_scale using Shakespeare data
132
+ We can accomplish similar results using `same_scale`.
133
+ ```python
134
+ hammock = hammock_plot.Hammock(data_df = df)
135
+ ax = hammock.plot(var=var_lst,hi_var = "speaker1", hi_value=hi_value,color=color_lst, bar_width=0.6,missing=True,
136
+ value_order ={"speaker1":speaker_order}, same_scale=["speaker1", "speaker2"] )
137
+ ```
138
+ <img src="image/shakespeare_scale.png" alt="Hammock plot for the Shakespeare data, with same_scale specified" width="600"/>
139
+
140
+ ### Example numerical_display_type using penguin data
141
+
142
+ We import the Shakespeare dataset:
143
+
144
+ ```python
145
+ import hammock_plot
146
+ import pandas as pd
147
+ df = pd.read_csv('./data/data_penguins.csv')
148
+ ```
149
+
150
+ We use `numerical_display_type` to control how we want to display our numerical data.
151
+
152
+ ```python
153
+ hammock = hammock_plot.Hammock(df)
154
+ ax = hammock.plot(
155
+ var= ["species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"],
156
+ hi_var="island",
157
+ hi_value=["Torgersen"],
158
+ missing=True,
159
+ numerical_display_type={"bill_length_mm":"box", "bill_depth_mm": "rugplot", "flipper_length_mm": "violin", "body_mass_g":"box"},
160
+ )
161
+ ```
162
+ <img src="image/penguin_display_violin.png" alt="Hammock plot for the penguin data, demonstrating numerical_display_type" width="600"/>
163
+
164
+ Box plots support multiple highlight values. Violin plots only support one highlight value.
165
+ ```python
166
+ ax = hammock.plot(
167
+ var= ["species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"],
168
+ hi_var="island",
169
+ hi_value=["Torgersen", "Biscoe"],
170
+ missing=True,
171
+ numerical_display_type={"bill_length_mm":"box", "bill_depth_mm": "box", "flipper_length_mm": "box", "body_mass_g":"box"},
172
+ )
173
+ ```
174
+ <img src="image/penguin_display_types.png" alt="Hammock plot for the penguin data, demonstrating numerical_display_type with multiple highlighting" width="600"/>
175
+
176
+ ## API Reference
177
+
178
+ ```
179
+ hammock()
180
+ ```
181
+
182
+ | Category | Parameter | Type | Description |
183
+ | --- | :-------- | :------- | :------------------------- |
184
+ | General | `var` | `List[str]` | List of variables to display. |
185
+ | | `value_order` | `Dict[str, List[int]]` | If specified, the order of the values in the plot follows the order of values in the list supplied in the dictionary. Only applicable to categorical variables |
186
+ | | `numerical_var_levels` | `Dict[str, int \| None]` | Specifies the number of subdivisions in the y-axis for numerical variables. Example: {"NumericalVarname": 9, "NumericalVarname2": None}. Default is 7. |
187
+ | | `numerical_display_type` | `Dict[str, str]` | Specifies the type of plot (rugplot, box plot, violin plot) for numerical variable display. Example: {"NumericalVarname": "rugplot", "NumericalVarname2": "violin", "NumericalVarname3": "box"}. Default is "rugplot". |
188
+ | | `missing` | `bool` | Whether or not to add a category for missing values at the bottom of the plot. If False, observations that have a missing value for any variable in the data frame (even those not used in the hammock plot) are removed. Default is False. |
189
+ | | `label` | `bool` | Whether or not to display labels between the plotting segments |
190
+ | | `unibar`| `bool` | Whether or not to display unibars between the plotting segments |
191
+ | Highlighting | `hi_var` | `str` | Variable to be highlighted. Default is none. |
192
+ | | `hi_value` | `List[str or int] or str or int` | Value(s) of `hi_var` to be highlighted. You can highlighted one or multiple values. You can also pass an expression (e.g. "x>1 and (x>5 or x<4)") in string when you want to specify a range for a numeric hi_var.|
193
+ | | `hi_box` | `str` | Controls how highlighted values are displayed within category labels. Options are "vertical" for vertically stacked color segments or "horizontal" for horizontally split color segments. Default is "vertical".|
194
+ | | `hi_missing` | `bool` | Whether or not missing values for `hi_var` should be highlighted. |
195
+ | | `color` | `List[str]` | List of colors corresponding to the list of values to be highlighted. Each color can be specified as a plain color name (e.g., `"red"`, `"yellow"`) or in the format `"color=alpha"` (e.g., `"red=0.5"`) to control transparency/intensity, where `alpha` is a decimal between 0 and 1. The default highlight color list is `["red", "green", "yellow", "lightblue", "orange", "gray", "brown", "olive", "pink", "cyan", "magenta"]`. |
196
+ | | `default_color` | `str` | Default color of plotting elements for boxes that are not highlighted. Default is "blue" |
197
+ | Manipulating Spacing and Layout | `uni_fraction` | `float` | Fraction of vertical space that should be populated by data. Adjusts the height of the data points. Defaults is 0.08. |
198
+ | | `space` | `float` |Fraction of horizontal space allocated to labels/univ. bars rather than to connecting boxes. Default is 0.3 |
199
+ | | `label_options` | `Dict[str, Dict[str, Any]]` | Manipulates the size and look of the labels. Args following the options in the website: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.text.html Example:{"ExampleVarname":{"fontsize":12,"fontstyle":"italic","fontweight":"black","color":"b"}} Default is None. |
200
+ | | `height` | `float` | Height of the plot in inches. Default is 10. |
201
+ | | `width` | `float` | Width of the plot in inches. Default is 15. Caution: Width too narrow may distort the plot. |
202
+ | | `alpha` | `float` | Alpha value for the colours in the plot. Float from 0-1. Default is 0.7. |
203
+ | | `min_bar_height` | `float` | Minimal bar height. Bars representing only a tiny fraction of the data may be so narrow, that they are invivisible in a plot. The default value tries to ensure this does not happen. Default is 0.1.
204
+ | Other options | `shape` | `str` | Shape of the boxes. "rectangle" (default) or "parallelogram". |
205
+ | | `same_scale` | `List[str]` | List of variables that have the same scale. Default is None. |
206
+ | | `display_figure` | `bool` | Whether or not to display the figure. This can be useful if you just want to save the plots. Default is 'True'. |
207
+ | | `save_path` | `str` | If it is not None, the figure will be saved to the given path with given name and format. Default is None. |
208
+
209
+
210
+ ## Historical context
211
+
212
+ In 1898, Sankey diagrams were developed to visualize flows of energy and materials.
213
+
214
+ In 1985, Inselberg popularized parallel coordinates to visualize continuous variables only. The central contribution is the use of parallel axes.
215
+
216
+ In 2003, Schonlau proposed the hammock plot. This was the first plot to visualize categorical data (or mixed categorical continuous data) on parallel axes.
217
+
218
+ In 2010, Rosvall proposed alluvial plots to visualize network variables over time. Rather than using bars to connect axes, alluvial plots use rounded curves. Alluvial plots are now also used to visualize categorical data.
219
+
220
+ There are several additional variations that also visualize categorical data including Parallel Set plots (Bendix et al, 2005), Right Angle plots (Hofmann and Vendettuoli, 2013),
221
+ and generalized parallel coordinate plots (GPCPs) (popularized by VanderPlas et al., 2023).
222
+
223
+ ### References
224
+ Bendix, F., Kosara, R., & Hauser, H. (2005). Parallel sets: visual analysis of categorical data. In IEEE Symposium on Information Visualization, 2005. INFOVIS 2005. 133-140.
225
+
226
+ Hofmann, H., & Vendettuoli, M. (2013). Common angle plots as perception-true visualizations of categorical associations. IEEE transactions on visualization and computer graphics, 19(12), 2297-2305.
227
+
228
+ Inselberg, A., & Dimsdale, B. (2009). Parallel coordinates. Human-Machine Interactive Systems, 199-233.
229
+
230
+ Rosvall, Martin, & Bergstrom, C.T. (2010) "Mapping change in large networks." PloS one 5.1: e8694.
231
+
232
+ Sankey, H. (1898). Introductory note on the thermal efficiency of steam-engines. report of
233
+ the committee appointed on the 31st march, 1896, to consider and report to the council
234
+ upon the subject of the definition of a standard or standards of thermal efficiency for
235
+ steam-engines: With an introductory note. In Minutes of proceedings of the institution
236
+ of civil engineers, Volume 134, pp. 278–283.
237
+
238
+ Schonlau M.
239
+ *[Visualizing Categorical Data Arising in the Health Sciences Using Hammock Plots.](http://www.schonlau.net/publication/03jsm_hammockplot.pdf)*
240
+ In Proceedings of the Section on Statistical Graphics, American Statistical Association; 2003
241
+
242
+ VanderPlas, S., Ge, Y., Unwin, A., & Hofmann, H. (2023).
243
+ Penguins Go Parallel: a grammar of graphics framework for generalized parallel coordinate plots.
244
+ Journal of Computational and Graphical Statistics, 1-16. (online first)
245
+
246
+ ### Other implementations of the hammock plot
247
+ There is also a Stata implementation `hammock` (available from the Stata archive SSC) and an R implementation as part of the package `ggparallel`.
248
+
249
+ [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)
250
+
251
+
252
+
253
+ ## Authors
254
+
255
+ - Tiancheng Yang t77yang@uwaterloo.ca
256
+
257
+
@@ -1,4 +1,5 @@
1
- from .hammock_plot import Hammock
2
-
3
- __author__ = "Tiancheng Yang"
4
- __author_email__ = "t77yang@uwaterloo.ca"
1
+ from .main import Hammock
2
+
3
+ __author__ = "Tiancheng Yang"
4
+ __author_email__ = "t77yang@uwaterloo.ca"
5
+ __all__ = ["Hammock"]