From 5fefb863b74d4c09f7297412417a6e0125658342 Mon Sep 17 00:00:00 2001 From: Daniel Stekhoven Date: Mon, 11 Sep 2023 13:34:36 +0200 Subject: [PATCH] Added multi-panel figure to analysis --- analysis.qmd | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/analysis.qmd b/analysis.qmd index 235b200..0b0becd 100644 --- a/analysis.qmd +++ b/analysis.qmd @@ -10,8 +10,12 @@ library(babynames) library(knitr) library(dplyr) library(ggplot2) +library(tidyr) +library(pheatmap) ``` +# Writing in Quarto part + Let's have a look at the first couple of rows in the data: ```{r} @@ -67,3 +71,45 @@ get_most_frequent(babynames, select_sex = "M") |> plot_top() ``` +# git and github part + +We want to plot multiple panels in a figure - an example for the most liked girl's name can be seen in @fig-mult-girls. + + +```{r} +#| label: fig-mult-girls +#| layout: [[50,50], [100]] +#| fig-cap: "Most favourite girl names - a closer look!" +#| fig-subcap: +#| - "Top 5 girl's names over the years" +#| - "Top 10 girl's names over the years" +#| - "Heatmap of top 30 girl's names versus years" +# get most frequent girl names from 2010 onwards +from_year <- 2010 +most_freq_girls <- get_most_frequent(babynames, select_sex = "F", + from = from_year) + +# plot top 5 girl names +most_freq_girls |> + plot_top(top = 5) + +# plot top 10 girl names +most_freq_girls |> + plot_top(top = 10) + +# get top 30 girl names in a matrix +# with names in rows and years in columns +prop_df <- babynames |> + filter(name %in% most_freq_girls$most_frequent$name[1:30] & sex == "F") |> + filter(year >= from_year) |> + select(year, name, prop) |> + pivot_wider(names_from = year, + values_from = prop) + +prop_mat <- as.matrix(prop_df[, 2:ncol(prop_df)]) +rownames(prop_mat) <- prop_df$name + +# create heatmap +pheatmap(prop_mat, cluster_cols = FALSE, scale = "row") +``` +