1 ### Graphs - cumulated ###
3 results4 <- read.table(
4 paste0(outdir, "/", country, "_output_v4", ifelse(IArest, "_IArestricted", ""), ".txt"),
5 header = TRUE, sep =";", dec=".")
6 note <- ifelse(IArest, "Note: Negative effects of IA are not shown", "")
7 results4$agegrp.labels <- factor(results4$agegrp,
8 labels = c("0-4 years", "5-14 years", "15-64 years", "Aged 65", "Total"))
11 pal <- c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#A65628", "#F781BF")
13 plotCumulSingle <- function(a, mortality=FALSE, lwd=2, ylab=NULL) {
16 ylb <- "Deaths / 100,000"
17 title <- paste0("Cumulated ",s," mortality attributable to ",t,", age group: ",unique(results4$agegrp.labels)[a+1])
20 ylb <- "Number of deaths"
21 title <- paste0("Cumulated ",s," number of deaths attributable to ",t,", age group: ",unique(results4$agegrp.labels)[a+1])
23 if (!is.null(ylab)) ylb <- ylab
25 if (is.na(ylb)) xlb <- NA
27 with(out[(out$agegrp==a),], {
28 plot(x=wk, y=get(yvar), type="n", xaxt="n", bty="l",
30 col=pal[1:length(levels(season))][as.integer(season)]
33 mtext(title, side=3, line=2, adj=0)
34 mtext(sprintf("FluMOMO v4 - week %s, %s", end_week, end_year), side=3, line=2, adj=1, cex=0.8)
36 axis(1, at=seq(1, max(wk), 4), labels = unique(floor(week))[seq(1, max(wk), 4)])
38 abline(v=seq(1, max(wk), 4), col="lightgray", lty="dotted")
39 mapply(function(s, col, l) {
40 points(x=wk[season==s], y=get(yvar)[season==s], col=col, type="l", lty=l, lwd=lwd)
41 }, s=levels(season), col=rev(pal[1:length(levels(season))]),
42 l=c(rep("dotted", length(levels(season))-1), "solid"))
47 plotCumulMultiple <- function(mortality=FALSE, lwd=2, ylab=NULL) {
48 par(mfrow=c(5,1), oma=c(6,3,2,0))
51 plotCumulSingle(a, mortality, ylab=NA)
52 legend("topleft", levels(results4$agegrp.labels)[a+1], bty="n", xpd=NA, cex=1.3, inset=c(0,-0.2))
54 mtext(paste0("Cumulated ",s, ifelse(mortality, " mortality", " number of deaths"), " attributable to ",t,", age group: ",unique(results4$agegrp.labels)[a+1]), side=3, line=0, adj=0, outer=TRUE)
55 mtext(sprintf("FluMOMO v4 - week %s, %s", end_week, end_year), side=3, line=0, adj=0.95, cex=0.8, outer=TRUE)
56 mtext(ifelse(mortality, "Deaths / 100,000", "Number of deaths"), side=2, line=1, outer=TRUE)
57 mtext("Week number", side=1, line=3, cex=0.8)
58 legend("bottom", legend=rev(levels(out$season)),
59 lty = c("solid", rep("dotted", length(levels(out$season))-1)),
60 col = pal[1:length(levels(out$season))], lwd=2, cex=1.2,
61 bty="n", horiz=TRUE, xpd=NA, inset=c(0,-0.59))
65 for (s in c("summer","winter","year")) {
67 out <- results4[!is.na(results4[,s]),
68 c("agegrp","agegrp.labels","year","week",paste0("cEd",t,"_",s),"N")]
69 colnames(out) <- c("agegrp","agegrp.labels","year","week","cd","N")
70 out$cm <- 100000 * out$cd / out$N
71 out[out$week==53,"week"] <- 52.5
73 out$wk <- with(out, 1 + (week-40)*(week>=40) + (week+12)*(week<=20))
74 out$season <- factor(paste0(as.character(with(out, year*(week>=40) + (year-1)*(week<=20))),"/",substr(as.character(with(out, year*(week>=40) + (year-1)*(week<=20))+1),3,4)))
78 out$season <- factor(out$year)
82 out$season <- factor(out$year)
84 out <- out[with(out, order(agegrp, wk)),]
85 png(paste0(outdir,"/cumulated_",t,"_deaths_agegroups_",s,"_v4", ifelse(IArest, "_IArestricted", ""), ".png"), width=1200, height=1600, res=130)
89 png(paste0(outdir,"/cumulated_",t,"_mr_agegroups_",s,"_v4", ifelse(IArest, "_IArestricted", ""), ".png"), width=1200, height=1600, res=130)
90 plotCumulMultiple(mortality=TRUE)
94 png(paste0(outdir,"/cumulated_",t,"_deaths_agegroup_",a,"_",s,"_v4", ifelse(IArest, "_IArestricted", ""), ".png"), width=1200, height=800, res=130)
97 legend("bottom", legend=rev(levels(out$season)),
98 lty = c("solid", rep("dotted", length(levels(out$season))-1)),
99 col = pal[1:length(levels(out$season))], lwd=2,
100 bty="n", horiz=TRUE, xpd=NA, inset=c(0,-0.35))
103 png(paste0(outdir,"/cumulated_",t,"_mr_agegroup_",a,"_",s,"_v4", ifelse(IArest, "_IArestricted", ""), ".png"), width=1200, height=800, res=130)
105 plotCumulSingle(a, mortality=TRUE)
106 legend("bottom", legend=rev(levels(out$season)),
107 lty = c("solid", rep("dotted", length(levels(out$season))-1)),
108 col = pal[1:length(levels(out$season))], lwd=2,
109 bty="n", horiz=TRUE, xpd=NA, inset=c(0,-0.35))
115 rm(plotCumulSingle, plotCumulMultiple, results4, a, s, t, out, note, pal)