diff --git a/functions.qmd b/functions.qmd index df68593..d46a8cc 100644 --- a/functions.qmd +++ b/functions.qmd @@ -723,6 +723,11 @@ For example, if you might want to do a vertical bar chart where you automaticall Since the bar chart is vertical, we also need to reverse the usual order to get the highest values at the top: ```{r} +#| fig-alt: | +#| Bar plot of clarify of diamonds, where clarity is on the y-axis and counts +#| are on the x-axis, and the bars are ordered in order of frequency: SI1, +#| VS2, SI2, VS1, VVS2, VVS1, IF, I1. + sorted_bars <- function(df, var) { df |> mutate({{ var }} := fct_rev(fct_infreq({{ var }}))) |> @@ -740,6 +745,10 @@ To work around this problem, we use the special operator `:=` which tidy evaluat Or maybe you want to make it easy to draw a bar plot just for a subset of the data: ```{r} +#| fig-alt: | +#| Bar plot of clarity of diamonds. The most common is SI1, then SI2, then +#| VS2, then VS1, then VVS2, then VVS1, then I1, then lastly IF. + conditional_bars <- function(df, condition, var) { df |> filter({{ condition }}) |>