-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdiamonds_dashboard.qmd
64 lines (54 loc) · 1.29 KB
/
diamonds_dashboard.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
---
title: "Diamonds dashboard"
author: Hadley Wickam
format: html
execute:
echo: false
---
```{r}
#| label: setup
#| include: false
library(tidyverse)
library(gt)
```
::: panel-tabset
## Plots
```{r}
#| layout: [[30,-5, 30, -5, 30], [100]]
ggplot(diamonds, aes(x = carat)) + geom_histogram(binwidth = 0.1)
ggplot(diamonds, aes(x = price)) + geom_histogram(binwidth = 500)
ggplot(diamonds, aes(x = cut, color = cut)) + geom_bar()
ggplot(diamonds, aes(x = carat, y = price, color = cut)) + geom_point()
```
## Summaries
```{r}
diamonds |>
select(price, carat, cut) |>
group_by(cut) |>
summarize(
across(where(is.numeric), list(mean = mean, median = median, sd = sd, IQR = IQR))
) |>
pivot_longer(cols = -cut) |>
pivot_wider(names_from = cut, values_from = value) |>
separate(name, into = c("var", "stat")) |>
mutate(
var = str_to_title(var),
stat = str_to_title(stat),
stat = if_else(stat == "Iqr", "IQR", stat)
) |>
group_by(var) |>
gt() |>
fmt_currency(columns = -stat, rows = 1:4, decimals = 0) |>
fmt_number(columns = -stat, rows = 5:8,) |>
cols_align(columns = -stat, align = "center") |>
cols_label(stat = "")
```
## Data
```{r}
diamonds |>
arrange(desc(carat)) |>
slice_head(n = 100) |>
select(price, carat, cut) |>
DT::datatable()
```
:::