@@ -11,7 +11,7 @@ data_curation <- function(articles, outbreaks, models, parameters, plotting,swit
1111 mutate(new_refs = ifelse(refs %in% refs [duplicated(refs )],
1212 paste0(sub(" \\ )$" , " " , refs ),letters [counter ]," )" ),
1313 refs )) | >
14- select(- counter ,- refs ) | >
14+ dplyr :: select(- counter ,- refs ) | >
1515 rename(refs = new_refs ) | >
1616 mutate(refs = str_to_title(refs ))
1717
@@ -70,7 +70,7 @@ data_curation <- function(articles, outbreaks, models, parameters, plotting,swit
7070 mutate(central = coalesce(parameter_value ,
7171 100 * cfr_ifr_numerator / cfr_ifr_denominator ,
7272 0.5 * (parameter_lower_bound + parameter_upper_bound ))) | >
73- select(- c(no_unc ))
73+ dplyr :: select(- c(no_unc ))
7474
7575 if (plotting ) {
7676 parameters <- param4plot
@@ -113,7 +113,8 @@ curation <- function(articles, outbreaks, models, parameters, plotting) {
113113# function to produce forest plot for given dataframe
114114forest_plot <- function (df , label , color_column , lims , text_size = 11 ,
115115 show_label = FALSE , custom_colours = NA ,
116- segment_show.legend = NA , sort = FALSE , qa_alpha = 1 ) {
116+ segment_show.legend = NA , sort = FALSE , qa_alpha = 1 ,
117+ point_size = 3 ) {
117118 stopifnot(length(unique(df $ parameter_unit [! is.na(df $ parameter_unit )])) == 1 )# values must have same units
118119
119120 if (sort ){
@@ -132,8 +133,8 @@ forest_plot <- function(df, label, color_column, lims, text_size = 11,
132133 df $ segment_alpha <- 1
133134
134135 if (qa_alpha != 1 ){
135- df [df $ qa_score < 0.5 , ]$ plot_alpha <- qa_alpha
136- df [df $ qa_score < 0.5 , ]$ segment_alpha <- 0.65 * qa_alpha
136+ df [df $ qa_score < = 0.5 , ]$ plot_alpha <- qa_alpha
137+ df [df $ qa_score < = 0.5 , ]$ segment_alpha <- 0.65 * qa_alpha
137138 }
138139
139140 cats <- length(unique(df [[color_column ]]))
@@ -142,22 +143,22 @@ forest_plot <- function(df, label, color_column, lims, text_size = 11,
142143 y = urefs , yend = urefs , color = .data [[color_column ]],),
143144 linewidth = 3 , alpha = df $ segment_alpha , show.legend = segment_show.legend ) +
144145 geom_errorbar(aes(xmin = parameter_uncertainty_lower_value , xmax = parameter_uncertainty_upper_value ,
145- y = urefs ),
146+ y = urefs , linetype = " Uncertainty " ),
146147 width = 0.25 , lwd = 0.5 , color = " black" , alpha = df $ plot_alpha ) +
147148 geom_errorbar(data = df [! df $ uncertainty_present ,],
148149 aes(xmin = parameter_2_lower_bound , xmax = parameter_2_upper_bound ,
149- y = urefs ),
150- width = 0.25 , lwd = 0.5 , color = " black" , linetype = " dashed " ,
150+ y = urefs , linetype = " Variability " ),
151+ width = 0.25 , lwd = 0.5 , color = " black" ,
151152 lineend = " square" , alpha = df [! (df $ uncertainty_present ),]$ plot_alpha ) +
152153 geom_errorbar(data = df [df $ uncertainty_present ,],
153154 aes(xmin = parameter_2_lower_bound , xmax = parameter_2_upper_bound ,
154- y = urefs ),
155- width = 0.25 , lwd = 0.5 , color = " black" , linetype = " dashed " ,
155+ y = urefs , linetype = " Variability " ),
156+ width = 0.25 , lwd = 0.5 , color = " black" ,
156157 lineend = " square" , position = position_nudge(y = - 0.25 ),
157158 alpha = df [df $ uncertainty_present ,]$ plot_alpha ) +
158159 geom_point(aes(x = parameter_value , y = urefs ,
159160 shape = parameter_value_type , fill = .data [[color_column ]]),
160- alpha = df $ plot_alpha , size = 3 , stroke = 1 , color = " black" )
161+ alpha = df $ plot_alpha , size = point_size , stroke = 1 , color = " black" )
161162
162163 if (all(df $ parameter_class == " Reproduction number" )) {
163164 gg <- gg +
@@ -172,6 +173,9 @@ forest_plot <- function(df, label, color_column, lims, text_size = 11,
172173 Other = 23 , `Central - unspecified` = 25 ),
173174 breaks = c(" Mean" , " Median" , " Unspecified" , " Other" ,
174175 " Central - unspecified" )) +
176+ scale_linetype_manual(name = " Variation Type" ,
177+ values = c(" Uncertainty" = " solid" ," Variability" = " dashed" ),
178+ breaks = c(" Uncertainty" , " Variability" )) +
175179 scale_x_continuous(limits = lims , expand = c(0 , 0 )) +
176180 scale_y_discrete(labels = setNames(df $ refs , df $ urefs )) +
177181 labs(x = label , y = NULL ) +
@@ -187,6 +191,9 @@ forest_plot <- function(df, label, color_column, lims, text_size = 11,
187191 Other = 23 , `Central - unspecified` = 25 ),
188192 breaks = c(" Mean" , " Median" , " Unspecified" , " Other" ,
189193 " Central - unspecified" )) +
194+ scale_linetype_manual(name = " Variation Type" ,
195+ values = c(" Uncertainty" = " solid" ," Variability" = " dashed" ),
196+ breaks = c(" Uncertainty" , " Variability" )) +
190197 scale_x_continuous(limits = lims , expand = c(0 , 0 )) +
191198 scale_y_discrete(labels = setNames(df $ refs , df $ urefs )) +
192199 labs(x = label , y = NULL ) +
@@ -196,9 +203,13 @@ forest_plot <- function(df, label, color_column, lims, text_size = 11,
196203 }
197204
198205 if (cats == 1 ) {
199- gg <- gg + guides(fill = " none" , color = " none" , shape = guide_legend(title = NULL ,order = 1 ))
206+ gg <- gg + guides(fill = " none" , color = " none" ,
207+ shape = guide_legend(title = NULL ,order = 1 ),
208+ linetype = guide_legend(title = NULL ,order = 2 ))
200209 } else {
201- gg <- gg + guides(fill = " none" , color = guide_legend(title = NULL ,order = 1 ), shape = guide_legend(title = NULL ,order = 2 ))}
210+ gg <- gg + guides(fill = " none" , color = guide_legend(title = NULL ,order = 1 ),
211+ shape = guide_legend(title = NULL ,order = 2 ),
212+ linetype = guide_legend(title = NULL , order = 3 ))}
202213
203214 if (show_label )
204215 gg <- gg + geom_text_repel(aes(x = coalesce(parameter_value ), y = urefs , label = population_country_ISO ), nudge_y = 0.5 , segment.color = " grey50" )
@@ -332,7 +343,7 @@ metamean_wrap <- function(dataframe, estmeansd_method,
332343 digits = digits , digits.sd = digits , digits.weight = digits ,
333344 col.diamond.lines = " black" ,col.diamond.common = colour , col.diamond.random = colour ,
334345 weight.study = " same" , col.square.lines = " black" , col.square = colour , col.study = " black" , col.inside = " black" ,
335- at = seq(lims [1 ],lims [2 ],by = 2 ), xlim = lims , xlab = label , fontsize = 10 , colgap.forest.left = paste0( colgap_shift ," cm" ))
346+ at = seq(lims [1 ],lims [2 ],by = 2 ), xlim = lims , xlab = label , fontsize = 13 , colgap.forest.left = paste0( colgap_shift ," cm" ))
336347 dev.off()
337348 } else {
338349 mtan <- metamean(data = dataframe ,
@@ -357,7 +368,7 @@ metamean_wrap <- function(dataframe, estmeansd_method,
357368 digits = digits , digits.sd = digits , digits.weight = digits ,
358369 col.diamond.lines = " black" ,col.diamond.common = colour , col.diamond.random = colour ,
359370 weight.study = " same" , col.square.lines = " black" , col.square = colour , col.study = " black" , col.inside = " black" ,
360- at = seq(lims [1 ],lims [2 ],by = 2 ), xlim = lims , xlab = label , fontsize = 10 )
371+ at = seq(lims [1 ],lims [2 ],by = 2 ), xlim = lims , xlab = label , fontsize = 13 )
361372 dev.off()
362373 }
363374
@@ -497,7 +508,7 @@ metagen_wrap <- function(dataframe, estmeansd_method,
497508 digits = digits , digits.sd = digits , digits.weight = digits ,
498509 col.diamond.lines = " black" ,col.diamond.common = colour , col.diamond.random = colour ,
499510 weight.study = " same" , col.square.lines = " black" , col.square = colour , col.study = " black" , col.inside = " black" ,
500- at = seq(lims [1 ],lims [2 ],by = 2 ), xlim = lims , xlab = label , fontsize = 10 )
511+ at = seq(lims [1 ],lims [2 ],by = 2 ), xlim = lims , xlab = label , fontsize = 11.5 )
501512 dev.off()
502513 } else {
503514 mtan <- metagen(data = dataframe ,
@@ -525,7 +536,7 @@ metagen_wrap <- function(dataframe, estmeansd_method,
525536 digits = digits , digits.sd = digits , digits.weight = digits ,
526537 col.diamond.lines = " black" ,col.diamond.common = colour , col.diamond.random = colour ,
527538 weight.study = " same" , col.square.lines = " black" , col.square = colour , col.study = " black" , col.inside = " black" ,
528- at = seq(lims [1 ],lims [2 ],by = 2 ), xlim = lims , xlab = label , fontsize = 10 )
539+ at = seq(lims [1 ],lims [2 ],by = 2 ), xlim = lims , xlab = label , fontsize = 11.5 )
529540 dev.off()
530541 }
531542
@@ -562,15 +573,24 @@ metaprop_wrap <- function(dataframe, subgroup,
562573 method.tau = " ML" )
563574
564575 png(file = " temp.png" , width = width , height = height , res = resolution )
576+ par(mar = c(2 , 2 , 2 , 1 ))
565577 forest(mtan , layout = " RevMan5" ,
566578 overall = plot_pooled , pooled.events = TRUE ,
567579 print.subgroup.name = FALSE , sort.subgroup = sort_by_subg ,
568580 study.results = plot_study ,
569581 digits = digits ,
570- col.diamond.lines = " black" ,col.diamond.common = colour , col.diamond.random = colour ,
571- col.subgroup = " black" , col.inside = " black" ,
572- weight.study = " same" , # col.square.lines = "green", col.square = "blue", #not working
573- at = at , xlim = xlim , xlab = " Case Fatality Ratio" , fontsize = 11 )
582+ col.diamond.lines = " black" ,col.diamond.common = colour ,
583+ col.diamond.random = colour ,
584+ col.square = colour , col.square.lines = " black" ,
585+ col.study = " black" , col.subgroup = " black" ,
586+ col.inside = " black" , weight.study = " same" ,
587+ at = at , xlim = xlim , xlab = " Case Fatality Ratio" ,
588+ fs.predict.labels = 11.5 ,
589+ fs.hetstat = 11 ,
590+ fs.test.subgroup = 11 ,
591+ fs.axis = 11 ,
592+ fontsize = 14 ,
593+ plotwidth = " 72.5mm" )
574594 dev.off()
575595 } else {
576596 mtan <- metaprop(data = dataframe ,
@@ -586,10 +606,17 @@ metaprop_wrap <- function(dataframe, subgroup,
586606 overall = plot_pooled , pooled.events = TRUE ,
587607 study.results = plot_study ,
588608 digits = digits ,
589- col.diamond.lines = " black" ,col.diamond.common = colour , col.diamond.random = colour ,
590- col.subgroup = " black" , col.inside = " black" ,
591- weight.study = " same" , # col.square.lines = "green", col.square = "blue", #not working
592- at = at , xlim = xlim , xlab = " Case Fatality Ratio" , fontsize = 11 )
609+ col.diamond.lines = " black" ,col.diamond.common = colour ,
610+ col.diamond.random = colour ,
611+ col.square = colour , col.square.lines = " black" ,
612+ col.subgroup = " black" , col.inside = " black" , weight.study = " same" ,
613+ at = at , xlim = xlim , xlab = " Case Fatality Ratio" ,
614+ fs.predict.labels = 11.5 ,
615+ fs.hetstat = 11 ,
616+ fs.test.subgroup = 11 ,
617+ fs.axis = 11 ,
618+ fontsize = 14 ,
619+ plotwidth = " 72.5mm" )
593620 dev.off()
594621 }
595622
0 commit comments