-
Notifications
You must be signed in to change notification settings - Fork 0
/
charts_piecharts.Rmd
156 lines (132 loc) · 4.35 KB
/
charts_piecharts.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
---
title: "Charts: Piecharts"
output:
html_document:
toc: true
toc_float:
collapsed: false
includes:
before_body: [includes/include_header.html, includes/include_header_navpage.html]
editor_options:
chunk_output_type: console
---
# What is a piechart?
Piecharts are useful visualisations for breaking down observations into a number of categories, the totals of which sum to 100% of the data. It is worth noting that it is often advisable to swap a barchart for a piechart, see
- Categories: For instance, species of animal e.g. human or iguana
- Values: For instance, number of animals of each species
Below is a comparison between a piechart and barchart build using `R` and the `highcharter` library.
<!--html_preserve-->
<div class="row">
<div class="col-md-6">
```{r basic_piechart, echo=FALSE, message=FALSE, warning=FALSE}
library("highcharter")
library("tidyverse")
my_data <- tribble(
~category, ~value,
"human", 3,
"non-human", 4,
"snake", 6,
"iguana", 8
)
my_data %>%
hchart(
type = "pie",
hcaes(
x = category,
y = value
)
) %>%
hc_plotOptions(pie = list(dataLabels = list(enabled = FALSE))) %>%
hc_size(width = "100%", height = "250px")
```
</div>
<div class="col-md-6">
```{r basic_barchart, echo=FALSE, message=FALSE, warning=FALSE}
library("highcharter")
library("tidyverse")
library("forcats")
my_data <- tribble(
~category, ~value,
"human", 3,
"non-human", 4,
"snake", 6,
"iguana", 8
)
my_data %>%
arrange(desc(value)) %>%
mutate(category = fct_reorder(category, value)) %>%
hchart(
type = "bar",
hcaes(
x = fct_reorder(category, rev(value)),
y = value
)
) %>%
hc_plotOptions(pie = list(dataLabels = list(enabled = FALSE))) %>%
hc_xAxis(title = list(text = "Category")) %>%
hc_size(width = "100%", height = "250px")
```
</div>
</div>
<!--/html_preserve-->
# Limitations of piecharts
Research in graphical perception - the visual decoding of information encoded in graphs - suggests that piecharts are often an inefficient option for visualising the differences between many categories; as it is difficult for the visual perception system to judge small differences in the sizes of sections in a piechart. It's also difficult to get exact measurements from piecharts, in the example above the barchart makes it clear that half as many observations are "non-human" as are categorised as "iguana".
Often you will simply hear the advice "never use a piechart, instead use a barchart" based on the work of [Cleveland and McGill](http://doi.org/10.2307/2288400){target='_blank'} (amongst others). But blanket bans on piecharts are definitely overkill. There are many examples of where piecharts can be useful and a lot of variation possible in the design of piecharts, here are some useful resources and below there's a very simple comparison between a piechart and donut chart.
- EagerEyes.org blogpost on [designing effective piecharts](https://eagereyes.org/techniques/pie-charts)
- Study into [judging error in piechart visualisations](https://kosara.net/papers/2016/Kosara-EuroVis-2016.pdf)
- Study into [differences between pie, area and sector charts](https://kosara.net/papers/2016/Skau-EuroVis-2016.pdf)
<!--html_preserve-->
<div class="row">
<div class="col-md-6">
```{r echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}
library("highcharter")
library("tidyverse")
my_data <- tribble(
~category, ~value,
"human", 3,
"non-human", 4,
"snake", 6,
"iguana", 8
)
my_data %>%
hchart(
type = "pie",
hcaes(
x = category,
y = value
)
) %>%
hc_plotOptions(pie = list(dataLabels = list(enabled = TRUE))) %>%
hc_size(width = "350px", height = "250px") %>%
hc_plotOptions(pie = list(
innerSize = 100,
depth = 45
), series = list(animation = FALSE))
```
</div>
<div class="col-md-6">
```{r echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}
library("highcharter")
library("tidyverse")
my_data <- tribble(
~category, ~value,
"human", 3,
"non-human", 4,
"snake", 6,
"iguana", 8
)
my_data %>%
hchart(
type = "pie",
hcaes(
x = category,
y = value
)
) %>%
hc_plotOptions(pie = list(dataLabels = list(enabled = TRUE))) %>%
hc_size(width = "350px", height = "250px") %>%
hc_plotOptions(series = list(animation = FALSE))
```
</div>
</div>
<!--/html_preserve-->