@@ -131,13 +131,11 @@ format_mr_results <- function(mr_res, exponentiate=FALSE, single_snp_method="Wal
131131
132132 dat <- dat [order(dat $ index ), ]
133133
134-
135134 dat <- dat [order(dat $ outcome ), ]
136135
137136 stopifnot(length(priority ) == 1 )
138137
139- if (priority %in% dat $ category )
140- {
138+ if (priority %in% dat $ category ) {
141139
142140 temp1 <- subset(dat , category == priority )
143141 temp2 <- subset(dat , category == " Other" )
@@ -149,7 +147,6 @@ format_mr_results <- function(mr_res, exponentiate=FALSE, single_snp_method="Wal
149147
150148 }
151149
152-
153150 return (dat )
154151}
155152
@@ -301,6 +298,7 @@ forest_plot_basic <- function(dat, section=NULL, colour_group=NULL, colour_group
301298 dat <- merge(dat , l , by = " lab" , all.x = TRUE )
302299 dat <- dat [rev(seq_len(nrow(dat ))), ]
303300
301+ if (utils :: packageVersion(" ggplot2" ) < = " 3.5.2" ) {
304302 p <- ggplot2 :: ggplot(dat , ggplot2 :: aes(x = effect , y = exposure )) +
305303 ggplot2 :: geom_rect(ggplot2 :: aes(fill = col ), xmin = - Inf , xmax = Inf , ymin = - Inf , ymax = Inf ) +
306304 ggplot2 :: geom_vline(xintercept = seq(ceiling(lo_orig ), ceiling(up ), by = 0.5 ), colour = " white" , size = 0.3 ) +
@@ -311,7 +309,7 @@ forest_plot_basic <- function(dat, section=NULL, colour_group=NULL, colour_group
311309 ggplot2 :: facet_grid(lab ~ . ) +
312310 ggplot2 :: scale_x_continuous(trans = trans , limits = c(lo , up )) +
313311 ggplot2 :: scale_colour_brewer(type = " qual" ) +
314- ggplot2 :: scale_fill_manual(values = c(" #eeeeee" , " #ffffff" ), guide = FALSE ) +
312+ ggplot2 :: scale_fill_manual(values = c(" #eeeeee" , " #ffffff" ), guide = " none " ) +
315313 ggplot2 :: theme(
316314 axis.line = ggplot2 :: element_blank(),
317315 axis.text.y = ggplot2 :: element_blank(),
@@ -336,6 +334,43 @@ forest_plot_basic <- function(dat, section=NULL, colour_group=NULL, colour_group
336334 ) +
337335 ggplot2 :: labs(y = NULL , x = xlabname , colour = " " , fill = NULL , title = main_title ) +
338336 outcome_labels
337+ } else {
338+ p <- ggplot2 :: ggplot(dat , ggplot2 :: aes(x = effect , y = exposure )) +
339+ ggplot2 :: geom_rect(ggplot2 :: aes(fill = col ), xmin = - Inf , xmax = Inf , ymin = - Inf , ymax = Inf ) +
340+ ggplot2 :: geom_vline(xintercept = seq(ceiling(lo_orig ), ceiling(up ), by = 0.5 ), colour = " white" , size = 0.3 ) +
341+ ggplot2 :: geom_vline(xintercept = null_line , colour = " #333333" , size = 0.3 ) +
342+ ggplot2 :: geom_errorbarh(ggplot2 :: aes(xmin = lo_ci , xmax = up_ci ), width = 0 , size = 0.4 , colour = " #aaaaaa" ) +
343+ ggplot2 :: geom_point(colour = " black" , size = 2.2 ) +
344+ point_plot +
345+ ggplot2 :: facet_grid(lab ~ . ) +
346+ ggplot2 :: scale_x_continuous(trans = trans , limits = c(lo , up )) +
347+ ggplot2 :: scale_colour_brewer(type = " qual" ) +
348+ ggplot2 :: scale_fill_manual(values = c(" #eeeeee" , " #ffffff" ), guide = " none" ) +
349+ ggplot2 :: theme(
350+ axis.line = ggplot2 :: element_blank(),
351+ axis.text.y = ggplot2 :: element_blank(),
352+ axis.ticks.y = ggplot2 :: element_blank(),
353+ axis.text.x = text_colour ,
354+ axis.ticks.x = tick_colour ,
355+ # strip.text.y=ggplot2::element_text(angle=360, hjust=0),
356+ strip.background = ggplot2 :: element_rect(fill = " white" , colour = " white" ),
357+ strip.text = ggplot2 :: element_text(family = " Courier New" , face = " bold" , size = 9 ),
358+ legend.position = " none" ,
359+ legend.direction = " vertical" ,
360+ panel.grid.minor.x = ggplot2 :: element_blank(),
361+ panel.grid.minor.y = ggplot2 :: element_blank(),
362+ panel.grid.major.y = ggplot2 :: element_blank(),
363+ plot.title = ggplot2 :: element_text(hjust = 0 , size = 12 , colour = title_colour ),
364+ plot.margin = ggplot2 :: unit(c(2 ,3 ,2 ,0 ), units = " points" ),
365+ plot.background = ggplot2 :: element_rect(fill = " white" ),
366+ panel.spacing = ggplot2 :: unit(0 ," lines" ),
367+ panel.background = ggplot2 :: element_rect(colour = " red" , fill = " grey" , size = 1 ),
368+ strip.text.y = ggplot2 :: element_blank()
369+ # strip.background = ggplot2::element_blank()
370+ ) +
371+ ggplot2 :: labs(y = NULL , x = xlabname , colour = " " , fill = NULL , title = main_title ) +
372+ outcome_labels
373+ }
339374 return (p )
340375}
341376
@@ -401,7 +436,7 @@ forest_plot_names <- function(dat, section=NULL, bottom=TRUE)
401436 ggplot2 :: facet_grid(lab ~ . ) +
402437 ggplot2 :: scale_x_continuous(limits = c(lo , up )) +
403438 ggplot2 :: scale_colour_brewer(type = " qual" ) +
404- ggplot2 :: scale_fill_manual(values = c(" #eeeeee" , " #ffffff" ), guide = FALSE ) +
439+ ggplot2 :: scale_fill_manual(values = c(" #eeeeee" , " #ffffff" ), guide = " none " ) +
405440 ggplot2 :: theme(
406441 axis.line = ggplot2 :: element_blank(),
407442 axis.text.y = ggplot2 :: element_blank(),
@@ -485,10 +520,8 @@ forest_plot <- function(mr_res, exponentiate=FALSE, single_snp_method="Wald rati
485520 ggplot2 :: theme(text = ggplot2 :: element_text(size = 10 ))
486521 )
487522
488- if (! by_category )
489- {
490- if (! in_columns )
491- {
523+ if (! by_category ) {
524+ if (! in_columns ) {
492525 return (forest_plot_basic(
493526 dat ,
494527 bottom = TRUE ,
@@ -506,8 +539,7 @@ forest_plot <- function(mr_res, exponentiate=FALSE, single_snp_method="Wald rati
506539 )
507540 count <- 2
508541 columns <- unique(dat $ exposure )
509- for (i in seq_along(columns ))
510- {
542+ for (i in seq_along(columns )) {
511543 l [[count ]] <- forest_plot_basic(
512544 dat ,
513545 section = NULL ,
@@ -534,13 +566,11 @@ forest_plot <- function(mr_res, exponentiate=FALSE, single_snp_method="Wald rati
534566 }
535567 }
536568
537- if (! in_columns )
538- {
569+ if (! in_columns ) {
539570 sec <- unique(as.character(dat $ category ))
540571 h <- rep(0 , length(sec ))
541572 l <- list ()
542- for (i in seq_along(sec ))
543- {
573+ for (i in seq_along(sec )) {
544574 l [[i ]] <- forest_plot_basic(
545575 dat ,
546576 sec [i ],
@@ -570,17 +600,15 @@ forest_plot <- function(mr_res, exponentiate=FALSE, single_snp_method="Wald rati
570600 l <- list ()
571601 h <- rep(0 , length(sec ))
572602 count <- 1
573- for (i in seq_along(sec ))
574- {
603+ for (i in seq_along(sec )) {
575604 h [i ] <- length(unique(subset(dat , category == sec [i ])$ outcome ))
576605 l [[count ]] <- forest_plot_names(
577606 dat ,
578607 sec [i ],
579608 bottom = i == length(sec )
580609 )
581610 count <- count + 1
582- for (j in seq_along(columns ))
583- {
611+ for (j in seq_along(columns )) {
584612 l [[count ]] <- forest_plot_basic(
585613 dat ,
586614 sec [i ],
0 commit comments