Skip to content

Commit a28ac72

Browse files
initial commit
1 parent cfa87fb commit a28ac72

File tree

1 file changed

+24
-19
lines changed
  • 3-Data-Visualization/R-11-visualization-proportions

1 file changed

+24
-19
lines changed

3-Data-Visualization/R-11-visualization-proportions/README.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ In this lesson, you will use a different nature-focused dataset to visualize pro
1818

1919
Mushrooms are very interesting. Let's import a dataset to study them:
2020

21-
```python
22-
import pandas as pd
23-
import matplotlib.pyplot as plt
24-
mushrooms = pd.read_csv('../../data/mushrooms.csv')
25-
mushrooms.head()
21+
```r
22+
mushrooms = read.csv('../../data/mushrooms.csv')
23+
head(mushrooms)
2624
```
2725
A table is printed out with some great data for analysis:
2826

@@ -32,24 +30,31 @@ A table is printed out with some great data for analysis:
3230
| Poisonous | Convex | Smooth | Brown | Bruises | Pungent | Free | Close | Narrow | Black | Enlarging | Equal | Smooth | Smooth | White | White | Partial | White | One | Pendant | Black | Scattered | Urban |
3331
| Edible | Convex | Smooth | Yellow | Bruises | Almond | Free | Close | Broad | Black | Enlarging | Club | Smooth | Smooth | White | White | Partial | White | One | Pendant | Brown | Numerous | Grasses |
3432
| Edible | Bell | Smooth | White | Bruises | Anise | Free | Close | Broad | Brown | Enlarging | Club | Smooth | Smooth | White | White | Partial | White | One | Pendant | Brown | Numerous | Meadows |
35-
| Poisonous | Convex | Scaly | White | Bruises | Pungent | Free | Close | Narrow | Brown | Enlarging | Equal | Smooth | Smooth | White | White | Partial | White | One | Pendant | Black | Scattered | Urban |
36-
33+
| Poisonous | Convex | Scaly | White | Bruises | Pungent | Free | Close | Narrow | Brown | Enlarging | Equal | Smooth | Smooth | White | White | Partial | White | One | Pendant | Black | Scattered | Urban
34+
| Edible | Convex |Smooth | Green | No Bruises| None |Free | Crowded | Broad | Black | Tapering | Equal | Smooth | Smooth | White | White | Partial | White | One | Evanescent | Brown | Abundant | Grasses
35+
|Edible | Convex | Scaly | Yellow | Bruises | Almond | Free | Close | Broad | Brown | Enlarging | Club | Smooth | Smooth | White | White | Partial | White | One | Pendant | Black | Numerous | Grasses
36+
3737
Right away, you notice that all the data is textual. You will have to convert this data to be able to use it in a chart. Most of the data, in fact, is represented as an object:
3838

39-
```python
40-
print(mushrooms.select_dtypes(["object"]).columns)
39+
```r
40+
names(mushrooms)
4141
```
4242

4343
The output is:
4444

4545
```output
46-
Index(['class', 'cap-shape', 'cap-surface', 'cap-color', 'bruises', 'odor',
47-
'gill-attachment', 'gill-spacing', 'gill-size', 'gill-color',
48-
'stalk-shape', 'stalk-root', 'stalk-surface-above-ring',
49-
'stalk-surface-below-ring', 'stalk-color-above-ring',
50-
'stalk-color-below-ring', 'veil-type', 'veil-color', 'ring-number',
51-
'ring-type', 'spore-print-color', 'population', 'habitat'],
52-
dtype='object')
46+
[1] "class" "cap.shape"
47+
[3] "cap.surface" "cap.color"
48+
[5] "bruises" "odor"
49+
[7] "gill.attachment" "gill.spacing"
50+
[9] "gill.size" "gill.color"
51+
[11] "stalk.shape" "stalk.root"
52+
[13] "stalk.surface.above.ring" "stalk.surface.below.ring"
53+
[15] "stalk.color.above.ring" "stalk.color.below.ring"
54+
[17] "veil.type" "veil.color"
55+
[19] "ring.number" "ring.type"
56+
[21] "spore.print.color" "population"
57+
[23] "habitat"
5358
```
5459
Take this data and convert the 'class' column to a category:
5560

@@ -123,10 +128,10 @@ Donut charts can be tweaked in several ways to change the labels. The labels in
123128
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.
124129
## Waffles!
125130

126-
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 [PyWaffle](https://pypi.org/project/pywaffle/) and use Matplotlib:
131+
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:
127132

128-
```python
129-
pip install pywaffle
133+
```r
134+
install.packages("waffle", repos = "https://cinc.rud.is")
130135
```
131136

132137
Select a segment of your data to group:

0 commit comments

Comments
 (0)