In [ ]:
#install.packages("pyramid", repos='http://cran.us.r-project.org')
In [ ]:
# Authors: Piotr Pokarowski, Anna Ochab-Marcinek
# Idea of normalization to age structure of general population: Zbigniew Piotrowski
library(pyramid)
# Data from (PP): https://www.medonet.pl/koronawirus/to-musisz-wiedziec,zasieg-koronawirusa-covid-19--mapa-,artykul,54726942.html
males= c(67, 75, 72, 66, 75, 71, 82, 84, 59, 65, 
         61, 56, 58, 77, 61, 65, 75, 83, 68, 51,
         77, 94, 61, 37, 71, 80, 71, 60, 72, 89, 
         82, 67, 75, 67, 70, 78, 67, 80, 71, 41, 
         71, 71, 68, 83, 43, 57, 73)
females=c(89, 68, 80, 87, 87, 80, 88, 77, 77, 83, 
          87, 75, 80, 87, 59, 70, 83, 32, 87, 73, 
          73, 84, 37, 57)

# Data from (AOM): https://www.populationpyramid.net/pl/polska/2019/
males_gen = c(6194917,3160180,2719072,2277815,2360657,1106234,541663)
females_gen = c(5915841,2938626,2678331,2375265,2794700,1629970,1194499)
In [ ]:
malesHist=hist(males, breaks=c(0,29,39,49,59,69,79,200))$counts
In [ ]:
femalesHist=hist(females, breaks=c(0,29,39,49,59,69,79,200))$counts;
In [ ]:
norm_malesHist=sum(hist(males, breaks=c(0,29,39,49,59,69,79,200))$counts);
norm_femalesHist=sum(hist(females, breaks=c(0,29,39,49,59,69,79,200))$counts);



ages=c('0-29','30-39','40-49','50-59','60-69','70-79','80-oo');
data = data.frame(malesHist,femalesHist,ages);
In [28]:
data1 = data.frame(100*as.vector(malesHist)/as.vector(males_gen),100*as.vector(femalesHist)/as.vector(females_gen),ages);

pyramid(data1, main="Case fatality rate for COVID-19 in Poland\n [% of population at a given age]",
        Lcol="steelblue", Rcol="hotpink1")