Skip to content

Commit

Permalink
Merge pull request #2 from stekhoven/1-create-a-panel-of-figures
Browse files Browse the repository at this point in the history
Added multi-panel figure to analysis
  • Loading branch information
stekhoven authored Sep 11, 2023
2 parents acfb20e + 5fefb86 commit 41d54bc
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions analysis.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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")
```

0 comments on commit 41d54bc

Please sign in to comment.