-
Notifications
You must be signed in to change notification settings - Fork 3
/
2-15_ggplot2_practicals_questions.qmd
87 lines (59 loc) · 2.17 KB
/
2-15_ggplot2_practicals_questions.qmd
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
## ggplot: Questions {.unnumbered}
Load the ggplot2 library (install it if you have to) and the diamonds data set using data()
```{r, eval=F}
# if needed install.packages("ggplot2")
library(ggplot2)
data("diamonds")
```
::: panel-tabset
### Question 1
Explore the data set using dim(), str() and help(), which variables are continuous, which variables are discrete? Is this data set ready for plotting with ggplot?
:::
::: panel-tabset
### Question 2
Use ggplot to plot a scatterplot of the relationship between the diamonds' carat a
:::
::: panel-tabset
### Question 3
Make all dots darkblue and set the alpha value to 0.1
:::
::: panel-tabset
### Question 4
Visualize the influence of the color of a diamond on its price by mapping the diamond color to the color aesthetic
:::
::: panel-tabset
### Question 5
Use a ggplot barplot to visualize diamond clarity depending on color, map diamond color to x and diamond clarity to fill
:::
::: panel-tabset
### Question 6
Create a boxplot of the carat of a diamond based on its clarity and add whiskers using stat_boxplot
:::
::: panel-tabset
### Question 7
Add a geom_point layer to the previous plot mapping the diamonds price to the color
:::
::: panel-tabset
### Question 8
Create a histogram of the price of the diamonds and separate the histograms into facets using diamond color, choose a good binwith or number of bins
:::
::: panel-tabset
### Question 9
Create a grid of facets of the same histogram by comparing both color and cut
:::
::: panel-tabset
### Question 10
Use `aggregate(diamonds, by = list(cut = diamonds$cut, color = diamonds$color), mean)` to calculate the mean of all variables by cut and color. Create a heatmap of the mean prices by cut and color using geom_tile
:::
::: panel-tabset
### Question 11
Change the title of the heatmap to "Average prices"
:::
::: panel-tabset
### Question 12
Change the gradient of the fill scale using 'scale_fill_gradient2'. Have it go from darkblue to white to darkred, set the midpoint to 4500
:::
::: panel-tabset
### Question 13
Choose and add a theme to the heatmap, or create a theme yourself using the options listed at <http://ggplot2.tidyverse.org/reference/theme.html>
:::