You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 3-Data-Visualization/R/11-visualization-proportions/README.md
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,7 @@ The output is:
59
59
Take this data and convert the 'class' column to a category:
60
60
61
61
```r
62
+
library(dplyr)
62
63
grouped=mushrooms %>%
63
64
group_by(class) %>%
64
65
summarise(count=n())
@@ -96,6 +97,7 @@ A somewhat more visually interesting pie chart is a donut chart, which is a pie
96
97
Take a look at the various habitats where mushrooms grow:
97
98
98
99
```r
100
+
library(dplyr)
99
101
habitat=mushrooms %>%
100
102
group_by(habitat) %>%
101
103
summarise(count=n())
@@ -116,30 +118,34 @@ The output is:
116
118
Here, you are grouping your data by habitat. There are 7 listed, so use those as labels for your donut chart:
117
119
118
120
```r
121
+
library(ggplot2)
119
122
library(webr)
120
123
PieDonut(habitat, aes(habitat, count=count))
121
124
```
122
125
123
126

124
127
125
-
This code draws a chart and a center circle, then adds that center circle in the chart. Edit the width of the center circle by changing `0.40` to another value.
128
+
This code uses the two libraries- ggplot2 and webr. Using the PieDonut function of the webr library, we can create a donut chart easily!
126
129
127
-
Donut charts can be tweaked in several ways to change the labels. The labels in particular can be highlighted for readability. Learn more in the [docs](https://matplotlib.org/stable/gallery/pie_and_polar_charts/pie_and_donut_labels.html?highlight=donut).
130
+
Donut charts in R can be made using only the ggplot2 library as well. You can learn more about it [here](https://www.r-graph-gallery.com/128-ring-or-donut-plot.html) and try it out yourself.
128
131
129
132
Now that you know how to group your data and then display it as a pie or donut, you can explore other types of charts. Try a waffle chart, which is just a different way of exploring quantity.
130
133
## Waffles!
131
134
132
-
A 'waffle' type chart is a different way to visualize quantities as a 2D array of squares. Try visualizing the different quantities of mushroom cap colors in this dataset. To do this, you need to install a helper library called [waffle](https://r-charts.com/part-whole/waffle-chart-ggplot2/) and use it to generate your visualization:
135
+
A 'waffle' type chart is a different way to visualize quantities as a 2D array of squares. Try visualizing the different quantities of mushroom cap colors in this dataset. To do this, you need to install a helper library called [waffle](https://cran.r-project.org/web/packages/waffle/waffle.pdf) and use it to generate your visualization:
Create a waffle chart by creating labels and then grouping your data:
@@ -169,8 +175,6 @@ Using a waffle chart, you can plainly see the proportions of cap colors of this
169
175
170
176

171
177
172
-
✅ Pywaffle supports icons within the charts that use any icon available in [Font Awesome](https://fontawesome.com/). Do some experiments to create an even more interesting waffle chart using icons instead of squares.
173
-
174
178
In this lesson, you learned three ways to visualize proportions. First, you need to group your data into categories and then decide which is the best way to display the data - pie, donut, or waffle. All are delicious and gratify the user with an instant snapshot of a dataset.
0 commit comments