-
Notifications
You must be signed in to change notification settings - Fork 0
/
wykres piramidy wieku.R
37 lines (31 loc) · 1.15 KB
/
wykres piramidy wieku.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
library(readxl)
df <- read_excel("2021 wiek.xlsx")
library(ggplot2)
library(magrittr)
library(dplyr)
library(vctrs)
library(scales)
# change male population to negative
df %>% mutate(
Population = ifelse(Gender=="M", Population*(-1),
Population*1))%>%
ggplot(aes(x = Age, y = Population, fill=Gender)) +
geom_bar(stat = "identity") +
#geom_line(aes(x = Age, y = Population, group = Gender)) +
coord_flip() +
scale_y_continuous(labels = abs) +
labs(x = "Grupa wiekowa", y = "Liczebność grupy", title = "Piramida ludności", fill = "Płeć")
# change male population to negative
df %>% mutate(
Population = ifelse(Gender=="M", Population*(-1),
Population*1))%>%
ggplot(aes(x = Population, y = Age, fill=Gender)) +
geom_bar(stat = "identity") +
#coord_flip() +
scale_fill_brewer(type = "seq",palette = 7) +
scale_x_continuous(labels = unit_format(unit = "M", scale = 1e-6))
df$age <- factor(df$Age)
apyramid::age_pyramid(data = df,
age_group = "age",
split_by = "Gender",
count = "Population")