r4ds/quarto/quarto-dashboard.qmd

64 lines
1.3 KiB
Plaintext
Raw Normal View History

---
title: "💍 Diamonds dashboard"
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()
```
:::