@@ -10,8 +10,12 @@ library(babynames)
1010library(knitr)
1111library(dplyr)
1212library(ggplot2)
13+ library(tidyr)
14+ library(pheatmap)
1315```
1416
17+ # Writing in Quarto part
18+
1519Let's have a look at the first couple of rows in the data:
1620
1721``` {r}
@@ -67,3 +71,45 @@ get_most_frequent(babynames, select_sex = "M") |>
6771 plot_top()
6872```
6973
74+ # git and github part
75+
76+ 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 .
77+
78+
79+ ``` {r}
80+ #| label: fig-mult-girls
81+ #| layout: [[50,50], [100]]
82+ #| fig-cap: "Most favourite girl names - a closer look!"
83+ #| fig-subcap:
84+ #| - "Top 5 girl's names over the years"
85+ #| - "Top 10 girl's names over the years"
86+ #| - "Heatmap of top 30 girl's names versus years"
87+ # get most frequent girl names from 2010 onwards
88+ from_year <- 2010
89+ most_freq_girls <- get_most_frequent(babynames, select_sex = "F",
90+ from = from_year)
91+
92+ # plot top 5 girl names
93+ most_freq_girls |>
94+ plot_top(top = 5)
95+
96+ # plot top 10 girl names
97+ most_freq_girls |>
98+ plot_top(top = 10)
99+
100+ # get top 30 girl names in a matrix
101+ # with names in rows and years in columns
102+ prop_df <- babynames |>
103+ filter(name %in% most_freq_girls$most_frequent$name[1:30] & sex == "F") |>
104+ filter(year >= from_year) |>
105+ select(year, name, prop) |>
106+ pivot_wider(names_from = year,
107+ values_from = prop)
108+
109+ prop_mat <- as.matrix(prop_df[, 2:ncol(prop_df)])
110+ rownames(prop_mat) <- prop_df$name
111+
112+ # create heatmap
113+ pheatmap(prop_mat, cluster_cols = FALSE, scale = "row")
114+ ```
115+
0 commit comments