Skip to content

Commit a3a65d6

Browse files
authored
Merge pull request #640 from remlapmot/ggplot2-v4
TwoSampleMR 0.6.18 - fixes for ggplot2 version 4
2 parents a62018f + 59d7e2f commit a3a65d6

File tree

17 files changed

+447
-157
lines changed

17 files changed

+447
-157
lines changed

.github/workflows/check-full.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
# max-parallel: 2
2929
matrix:
3030
config:
31-
- {os: macos-latest, r: 'release'}
31+
- {os: macos-15, r: 'release'}
3232
- {os: windows-latest, r: 'release'}
3333
- {os: ubuntu-latest, r: 'release'}
3434
- {os: ubuntu-latest, r: 'oldrel-1'}
@@ -37,8 +37,7 @@ jobs:
3737
- {os: ubuntu-latest, r: '4.3.2'}
3838
- {os: ubuntu-latest, r: 'oldrel-3'}
3939
- {os: ubuntu-latest, r: 'oldrel-4'}
40-
- {os: macos-15, r: 'release'}
41-
- {os: macos-13, r: 'release'}
40+
- {os: macos-14, r: 'release'}
4241
# - {os: ubuntu-24.04-arm, r: 'release', rspm: 'no' }
4342

4443
env:

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ vignettes/*.html
1919
docs
2020
tests/testthat/*.pdf
2121
README.html
22+
vignettes/filename.pdf
23+
vignettes/filename.png
24+
vignettes/plot1.pdf
25+
vignettes/mr_report.md
26+
vignettes/figure/*.png
27+
vignettes/*.html

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: TwoSampleMR
22
Title: Two Sample MR Functions and Interface to MRC Integrative
33
Epidemiology Unit OpenGWAS Database
4-
Version: 0.6.17
4+
Version: 0.6.18
55
Authors@R: c(
66
person("Gibran", "Hemani", , "[email protected]", role = c("aut", "cre"),
77
comment = c(ORCID = "0000-0003-0920-1055")),

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# TwoSampleMR v0.6.18
2+
3+
(Release date 2025-07-15)
4+
5+
* Fixes to `mr_forest_plot()`, `forest_plot_1_to_many()`, `mr_leaveoneout_plot()`, and `mr_scatter_plot()` for compatibility with the forthcoming release of version 4 of **ggplot2**.
6+
* Made some minor improvements in the *Perform MR* vignette including adding back several of the forest plots.
7+
18
# TwoSampleMR v0.6.17
29

310
(Release date 2025-06-22)

R/forest_plot2.R

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)