Skip to content

Commit

Permalink
added some 2023 analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
aviezerl committed Jul 3, 2024
1 parent 7c7e92d commit 8bc48fc
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 6 deletions.
12 changes: 6 additions & 6 deletions streamlit/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def set_custom_css():
"years_note": "Years that include less than 5 babies are shown as 0. Data was downloaded from the",
"additional_analysis": "Additional analysis can be found",
"here": "here",
"analysis_2022": "2022 analysis",
"analysis_2023": "2023 analysis",
"year_axis": "Year",
"babies_axis": "# of babies",
"percent_axis": "% of babies",
Expand All @@ -71,7 +71,7 @@ def set_custom_css():
"years_note": "שנים הכוללות פחות מ-5 תינוקות מוצגות כ-0. הנתונים הורדו מ",
"additional_analysis": "ניתוח נוסף ניתן למצוא",
"here": "כאן",
"analysis_2022": "ניתוח 2022",
"analysis_2023": "ניתוח 2023",
"year_axis": "שנה",
"babies_axis": "מספר תינוקות",
"percent_axis": "אחוז תינוקות",
Expand Down Expand Up @@ -263,16 +263,16 @@ def main():
unsafe_allow_html=True,
)
st.markdown(
f'<div class="rtl">{t["years_note"]} <a href="https://www.cbs.gov.il/he/publications/LochutTlushim/2020/%D7%A9%D7%9E%D7%95%D7%AA-%D7%A4%D7%A8%D7%98%D7%99%D7%99%D7%9D.xlsx">הלשכה המרכזית לסטטיסטיקה</a>. 2022 הנתונים הורדו מ <a href="https://www.cbs.gov.il/he/mediarelease/Pages/2023/%D7%94%D7%A9%D7%9E%D7%95%D7%AA-%D7%94%D7%A4%D7%A8%D7%98%D7%99%D7%99%D7%9D-%D7%A9%D7%A0%D7%99%D7%AA%D7%A0%D7%95-%D7%9C%D7%99%D7%9C%D7%99%D7%93%D7%99-2022.aspx">{t["here"]}</a>. {t["additional_analysis"]} <a href="https://aviezerl.github.io/babynamesIL/articles/babynamesIL.html">{t["here"]}</a>. <a href="https://aviezerl.github.io/babynamesIL/articles/2022.html">{t["analysis_2022"]}</div>',
f'<div class="rtl">{t["years_note"]} <a href="https://www.cbs.gov.il/he/publications/LochutTlushim/2020/%D7%A9%D7%9E%D7%95%D7%AA-%D7%A4%D7%A8%D7%98%D7%99%D7%99%D7%9D.xlsx">הלשכה המרכזית לסטטיסטיקה</a>. <a href="https://www.cbs.gov.il/he/mediarelease/Pages/2023/%D7%94%D7%A9%D7%9E%D7%95%D7%AA-%D7%94%D7%A4%D7%A8%D7%98%D7%99%D7%99%D7%9D-%D7%A9%D7%A0%D7%99%D7%AA%D7%A0%D7%95-%D7%9C%D7%99%D7%9C%D7%99%D7%93%D7%99-2022.aspx">[2022]</a>, <a href="https://www.cbs.gov.il/he/mediarelease/Pages/2024/%D7%94%D7%A9%D7%9E%D7%95%D7%AA-%D7%94%D7%A4%D7%A8%D7%98%D7%99%D7%99%D7%9D-%D7%A9%D7%A0%D7%99%D7%AA%D7%A0%D7%95-%D7%9C%D7%99%D7%9C%D7%99%D7%93%D7%99-2023.aspx">[2023]</a>. {t["additional_analysis"]} <a href="https://aviezerl.github.io/babynamesIL/articles/babynamesIL.html">{t["here"]}</a>. <a href="https://aviezerl.github.io/babynamesIL/articles/2023.html">{t["analysis_2023"]}</a></div>',
unsafe_allow_html=True,
)
st.markdown("</div>", unsafe_allow_html=True)
else:
st.write(
f"There were {total_male} male and {total_female} female babies named {name} from 1948 to 2023.\n\n"
f"{t['years_note']} [{'Israeli Central Bureau of Statistics'}](https://www.cbs.gov.il/he/publications/LochutTlushim/2020/%D7%A9%D7%9E%D7%95%D7%AA-%D7%A4%D7%A8%D7%98%D7%99%D7%99%D7%9D.xlsx). "
f"2022 {'data was downloaded from'} [{t['here']}](https://www.cbs.gov.il/he/mediarelease/Pages/2023/%D7%94%D7%A9%D7%9E%D7%95%D7%AA-%D7%94%D7%A4%D7%A8%D7%98%D7%99%D7%99%D7%9D-%D7%A9%D7%A0%D7%99%D7%AA%D7%A0%D7%95-%D7%9C%D7%99%D7%9C%D7%99%D7%93%D7%99-2022.aspx). "
f"{t['additional_analysis']} [{t['here']}](https://aviezerl.github.io/babynamesIL/articles/babynamesIL.html). [{t['analysis_2022']}](https://aviezerl.github.io/babynamesIL/articles/2022.html). "
f"{t['years_note']} [{'Israeli Central Bureau of Statistics'}](https://www.cbs.gov.il/he/publications/LochutTlushim/2020/%D7%A9%D7%9E%D7%95%D7%AA-%D7%A4%D7%A8%D7%98%D7%99%D7%99%D7%9D.xlsx), "
f"[2022](https://www.cbs.gov.il/he/mediarelease/Pages/2023/%D7%94%D7%A9%D7%9E%D7%95%D7%AA-%D7%94%D7%A4%D7%A8%D7%98%D7%99%D7%99%D7%9D-%D7%A9%D7%A0%D7%99%D7%AA%D7%A0%D7%95-%D7%9C%D7%99%D7%9C%D7%99%D7%93%D7%99-2022.aspx), [2023](https://www.cbs.gov.il/he/mediarelease/Pages/2024/%D7%94%D7%A9%D7%9E%D7%95%D7%AA-%D7%94%D7%A4%D7%A8%D7%98%D7%99%D7%99%D7%9D-%D7%A9%D7%A0%D7%99%D7%AA%D7%A0%D7%95-%D7%9C%D7%99%D7%9C%D7%99%D7%93%D7%99-2023.aspx). "
f"{t['additional_analysis']} [{t['here']}](https://aviezerl.github.io/babynamesIL/articles/babynamesIL.html). [{t['analysis_2023']}](https://aviezerl.github.io/babynamesIL/articles/2023.html). "
)


Expand Down
119 changes: 119 additions & 0 deletions vignettes/articles/2023.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
title: "2023"
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r setup}
library(babynamesIL)
library(tidyverse)
library(tgstat)
theme_set(theme_classic())
```

# 2023

## Top 10 names

```{r top10, fig.width = 15, fig.height = 15}
babynamesIL %>%
filter(year == 2023) %>%
mutate(sector = factor(sector, levels = c("Jewish", "Muslim", "Christian", "Druze", "Other"))) %>%
group_by(sector, sex) %>%
slice_max(order_by = n, n = 20) %>%
arrange(sector, sex, desc(n)) %>%
mutate(name = forcats::fct_inorder(name)) %>%
ggplot(aes(x = name, y = n)) +
geom_col() +
facet_wrap(sector ~ sex, scales = "free", ncol = 2) +
ylab("total #") +
xlab("") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
```

## Names that changed the most in popularity

```{r change, fig.width = 10, fig.height = 8}
babynamesIL %>%
filter(year %in% c(2023, 2022), sector == "Jewish") %>%
pivot_wider(names_from = year, values_from = c(prop, n)) %>%
filter(!is.na(prop_2023) & !is.na(prop_2022)) %>%
mutate(prop_diff = prop_2023 - prop_2022) %>%
arrange(sex, desc(abs(prop_diff))) %>%
group_by(sex) %>%
slice(1:30) %>%
ggplot(aes(x = n_2023, y = prop_diff, color = sex, label = name)) +
geom_point() +
theme_classic() +
ggsci::scale_color_aaas() +
ggrepel::geom_text_repel(size = 6) +
scale_y_continuous(label = scales::percent) +
geom_hline(yintercept = 0) +
ylab("Difference in %") +
xlab("# in 2023")
```

## Named that shifted from 'male' to 'female' and vice versa

```{r change2, fig.width = 15, fig.height = 15}
unisex_data <- babynamesIL %>%
filter(sector == "Jewish", year %in% c(2022, 2023)) %>%
pivot_wider(names_from = "sex", values_from = c("n", "prop"), values_fill = 0) %>%
filter(n_M > 0 & n_F > 0) %>%
mutate(ratio = n_M / n_F) %>%
group_by(name) %>%
filter(abs(ratio[1] - ratio[2]) >= 0.2) %>%
ungroup()
unisex_data %>%
ggplot(aes(x = n_M, y = n_F, label = name, color = factor(year, levels = c(2023, 2022)), group = name)) +
geom_point() +
ggsci::scale_color_nejm(name = "year") +
geom_line(color = "gray") +
scale_x_log10() +
scale_y_log10() +
ggrepel::geom_text_repel() +
geom_abline() +
xlab("# male") +
ylab("# female")
```

Only names that became more male:

```{r change3, fig.width = 15, fig.height = 15}
unisex_data %>%
group_by(name) %>%
filter(ratio[1] > ratio[2]) %>%
ggplot(aes(x = n_M, y = n_F, label = name, color = factor(year, levels = c(2023, 2022)), group = name)) +
geom_point() +
ggsci::scale_color_nejm(name = "year") +
geom_line(color = "gray") +
scale_x_log10() +
scale_y_log10() +
ggrepel::geom_text_repel() +
geom_abline() +
xlab("# male") +
ylab("# female")
```

Only names that became more female:

```{r change4, fig.width = 15, fig.height = 15}
unisex_data %>%
group_by(name) %>%
filter(ratio[2] > ratio[1]) %>%
ggplot(aes(x = n_M, y = n_F, label = name, color = factor(year, levels = c(2023, 2022)), group = name)) +
geom_point() +
ggsci::scale_color_nejm(name = "year") +
geom_line(color = "gray") +
scale_x_log10() +
scale_y_log10() +
ggrepel::geom_text_repel() +
geom_abline() +
xlab("# male") +
ylab("# female")
```

0 comments on commit 8bc48fc

Please sign in to comment.