From 9db5fc84b64211b3397053707e01d319d1d32a21 Mon Sep 17 00:00:00 2001 From: "Arnaud M. Wolfer" Date: Tue, 8 Nov 2022 17:38:24 +0100 Subject: [PATCH 1/5] Bugfix in plotHistogram error message --- DESCRIPTION | 4 ++-- inst/NEWS | 4 ++-- tests/testthat/test_plotHistogram.R | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 591f3e3..de70d0c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: peakPantheR Title: Peak Picking and Annotation of High Resolution Experiments -Version: 1.13.0 -Date: 2022-08-05 +Version: 1.13.1 +Date: 2022-11-06 Authors@R: c(person("Arnaud", "Wolfer", email = "adwolfer@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5856-3218")), person("Goncalo", "Correia", email = "gscorreia89@gmail.com", role = "aut", comment = c(ORCID = "0000-0001-8271-9294")), person("Jake", "Pearce", email = "jake.pearce@gmail.com", role = "ctb"), diff --git a/inst/NEWS b/inst/NEWS index 4a77d4c..8d97bfa 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -1,2 +1,2 @@ -Changes in version 1.11.1 (2022-08-05) -- Bugfix: manage mxML files without timestamp tag \ No newline at end of file +Changes in version 1.13.1 (2022-11-06) +- Bugfix: plotHistogram changing warning message \ No newline at end of file diff --git a/tests/testthat/test_plotHistogram.R b/tests/testthat/test_plotHistogram.R index d6253dc..0f0d8e7 100644 --- a/tests/testthat/test_plotHistogram.R +++ b/tests/testthat/test_plotHistogram.R @@ -18,7 +18,7 @@ test_that('histogram and density, with NA in input', { # input tmp_input <- c(NA, input_val, NA) # expected message - expected_message <- "`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.\n" + expected_message <- "`stat_bin()` using `bins = 30`. Pick better value with `binwidth`." # expected values expected_data <- data.frame(x=input_val) From dd3a7d92f4cc9658ce271252a97b9467e35a54e9 Mon Sep 17 00:00:00 2001 From: "Arnaud M. Wolfer" Date: Tue, 8 Nov 2022 17:53:31 +0100 Subject: [PATCH 2/5] update github Action to new r-lib and bioc --- .github/workflows/check-bioc-devel.yml | 14 +++++++------- .github/workflows/check-bioc.yml | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/check-bioc-devel.yml b/.github/workflows/check-bioc-devel.yml index ebeb468..5e0d6c9 100644 --- a/.github/workflows/check-bioc-devel.yml +++ b/.github/workflows/check-bioc-devel.yml @@ -53,9 +53,9 @@ jobs: fail-fast: false matrix: config: - - { os: ubuntu-latest, r: 'devel', bioc: '3.16', cont: "bioconductor/bioconductor_docker:devel", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } - - { os: macOS-latest, r: 'devel', bioc: '3.16'} - - { os: windows-latest, r: 'devel', bioc: '3.16'} + - { os: ubuntu-latest, r: 'devel', bioc: '3.17', cont: "bioconductor/bioconductor_docker:devel", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } + - { os: macOS-latest, r: 'devel', bioc: '3.17'} + - { os: windows-latest, r: 'devel', bioc: '3.17'} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} @@ -75,7 +75,7 @@ jobs: echo ".libPaths('/__w/_temp/Library')" > ~/.Rprofile ## Most of these steps are the same as the ones in - ## https://github.com/r-lib/actions/blob/master/examples/check-standard.yaml + ## https://github.com/r-lib/actions/blob/v2/examples/check-standard.yaml ## If they update their steps, we will also need to update ours. - name: Checkout Repository uses: actions/checkout@v2 @@ -83,14 +83,14 @@ jobs: ## R is already included in the Bioconductor docker images - name: Setup R from r-lib if: runner.os != 'Linux' - uses: r-lib/actions/setup-r@master + uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} ## pandoc is already included in the Bioconductor docker images - name: Setup pandoc from r-lib if: runner.os != 'Linux' - uses: r-lib/actions/setup-pandoc@master + uses: r-lib/actions/setup-pandoc@v2 - name: Query dependencies run: | @@ -269,7 +269,7 @@ jobs: - name: Upload check results if: failure() - uses: actions/upload-artifact@master + uses: actions/upload-artifact@v2 with: name: ${{ runner.os }}-biocversion-devel-r-devel-results path: check diff --git a/.github/workflows/check-bioc.yml b/.github/workflows/check-bioc.yml index a48f1b7..37af64b 100644 --- a/.github/workflows/check-bioc.yml +++ b/.github/workflows/check-bioc.yml @@ -53,9 +53,9 @@ jobs: fail-fast: false matrix: config: - - { os: ubuntu-latest, r: '4.2', bioc: '3.15', cont: "bioconductor/bioconductor_docker:RELEASE_3_15", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } - - { os: macOS-latest, r: '4.2', bioc: '3.15'} - - { os: windows-latest, r: '4.2', bioc: '3.15'} + - { os: ubuntu-latest, r: '4.2', bioc: '3.16', cont: "bioconductor/bioconductor_docker:RELEASE_3_16", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } + - { os: macOS-latest, r: '4.2', bioc: '3.16'} + - { os: windows-latest, r: '4.2', bioc: '3.16'} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} @@ -75,7 +75,7 @@ jobs: echo ".libPaths('/__w/_temp/Library')" > ~/.Rprofile ## Most of these steps are the same as the ones in - ## https://github.com/r-lib/actions/blob/master/examples/check-standard.yaml + ## https://github.com/r-lib/actions/blob/v2/examples/check-standard.yaml ## If they update their steps, we will also need to update ours. - name: Checkout Repository uses: actions/checkout@v2 @@ -83,14 +83,14 @@ jobs: ## R is already included in the Bioconductor docker images - name: Setup R from r-lib if: runner.os != 'Linux' - uses: r-lib/actions/setup-r@master + uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} ## pandoc is already included in the Bioconductor docker images - name: Setup pandoc from r-lib if: runner.os != 'Linux' - uses: r-lib/actions/setup-pandoc@master + uses: r-lib/actions/setup-pandoc@v2 - name: Query dependencies run: | @@ -103,16 +103,16 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.R_LIBS_USER }} - key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_15-r-4.2-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_15-r-4.2- + key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_16-r-4.2-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_16-r-4.2- - name: Cache R packages on Linux if: "!contains(github.event.head_commit.message, '/nocache') && runner.os == 'Linux' " uses: actions/cache@v2 with: path: /home/runner/work/_temp/Library - key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_15-r-4.2-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_15-r-4.2- + key: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_16-r-4.2-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ env.cache-version }}-${{ runner.os }}-biocversion-RELEASE_3_16-r-4.2- - name: Install Linux system dependencies if: runner.os == 'Linux' @@ -267,7 +267,7 @@ jobs: - name: Upload check results if: failure() - uses: actions/upload-artifact@master + uses: actions/upload-artifact@v2 with: - name: ${{ runner.os }}-biocversion-RELEASE_3_15-r-4.2-results + name: ${{ runner.os }}-biocversion-RELEASE_3_16-r-4.2-results path: check From fdacd80b7ede31c0422874022fabeec5ab38a15f Mon Sep 17 00:00:00 2001 From: "Arnaud M. Wolfer" Date: Sun, 11 Dec 2022 22:48:27 +0100 Subject: [PATCH 3/5] fix plotPeakwidth due to ggplot2 changes --- DESCRIPTION | 3 +- R/peakPantheR_plotPeakwidth.R | 196 +++++++++--------- R/plotEICDetectedPeakwidth.R | 2 +- inst/NEWS | 6 +- .../test_annotationDiagnosticMultiplot.R | 2 +- .../testthat/test_peakPantheR_plotPeakwidth.R | 18 +- 6 files changed, 115 insertions(+), 112 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index de70d0c..cde79d6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,8 @@ Imports: shinycssloaders (>= 1.0.0), DT (>= 0.15), pracma (>= 2.2.3), - utils + utils, + lubridate biocViews: MassSpectrometry, Metabolomics, PeakDetection License: GPL-3 BugReports: https://github.com/phenomecentre/peakPantheR/issues/new diff --git a/R/peakPantheR_plotPeakwidth.R b/R/peakPantheR_plotPeakwidth.R index d59180d..fd94441 100644 --- a/R/peakPantheR_plotPeakwidth.R +++ b/R/peakPantheR_plotPeakwidth.R @@ -61,40 +61,48 @@ peakPantheR_plotPeakwidth <- function(apexValue, widthMin=NULL, widthMax = NULL, acquTime=NULL, varName="variable", sampleColour = NULL, rotateAxis = FALSE, verbose = TRUE) { - # Check input + coord_y_datetime <- function(xlim = NULL, ylim = NULL, expand = TRUE) { + if (!is.null(ylim)) { ylim <- lubridate::as_datetime(ylim) } + ggplot2::coord_cartesian(xlim = xlim, ylim = ylim, expand = expand) + } + + ## Check input resInp <- plotPeakwidth_checkInput(apexValue, widthMin, widthMax, acquTime, sampleColour, verbose) nbSpl <- resInp$nbSpl; useRunOrder <- resInp$useRunOrder useWidth <- resInp$useWidth; colourSpl <- resInp$colourSpl sampleIDColour <- resInp$sampleIDColour - # Init plot draw default x/y with y the variable, rotate later if required + ## Init plot draw default x/y will fill depending on rotation p <- ggplot2::ggplot(NULL, ggplot2::aes(x), environment = environment()) + - ggplot2::theme_bw() + - ggplot2::ylab(varName) - + ggplot2::theme_bw() # set fill and colour scale, with one color per sample ID p <- p + ggplot2::scale_colour_manual(values = colourSpl, guide = "none") p <- p + ggplot2::scale_fill_manual(values = colourSpl, guide = "none") - # tmp x axis + ## tmp main axis if (useRunOrder) { x_axis <- acquTime } else { - if (rotateAxis) { - x_axis <- seq(nbSpl - 1, 0) #first spectra on top - } else { - x_axis <- seq(0, nbSpl - 1) #first spectra on left - } + x_axis <- seq(0, nbSpl - 1) #first spectra on left } - - # Plot peakwidth, apex values and apex points - p <- plotPeakwidth_plotWidthApex(p, useWidth, useRunOrder, x_axis, widthMin, - widthMax, sampleIDColour, apexValue, acquTime, verbose) - # Rotate axis - p <- plotPeakwidth_rotateAxis(p, rotateAxis, useRunOrder, verbose) - + ## Plot peakwidth, apex values and apex points (flip x/y if rotateAxis) + # must rotateAxis inside the function otherwise the checks for NA wouldn't + # work with flipped inputs + p <- plotPeakwidth_plotWidthApex(p, useWidth, rotateAxis, x_axis, + widthMin, widthMax, sampleIDColour, apexValue, verbose) + + # some expected messages + if (verbose) { + if (useRunOrder) { message("Values plotted by run order") + } else { message("Values plotted by input order") } + } + + ## final ordering and axis labelling + p <- plotPeakwidth_rotateAxis_setLabels <- function(p, rotateAxis, + useRunOrder, acquTime, verbose) + return(p) } @@ -153,98 +161,90 @@ plotPeakwidth_checkInput <- function(apexValue, widthMin, widthMax, acquTime, return(list(nbSpl=nbSpl, useRunOrder=useRunOrder, useWidth=useWidth, colourSpl=colourSpl, sampleIDColour=sampleIDColour)) } -# Plot peakwidth, apex values and apex points -plotPeakwidth_plotWidthApex <- function(p, useWidth, useRunOrder, x_axis, - widthMin, widthMax, sampleIDColour, apexValue, acquTime, verbose) { - # peak width (must go first to be the bottom most layer) +# Plot peakwidth, apex values and apex points (flip x/y if rotateAxis) +plotPeakwidth_plotWidthApex <- function(p, useWidth, rotateAxis, + x_axis, widthMin, widthMax, sampleIDColour, apexValue, verbose) { + + ## Apex value + # add apex point (add the color ID to each point, and an ID pointing to the + # black stroke) + tmp_pt <- data.frame(x = x_axis, y = apexValue, colr = sampleIDColour, + stringsAsFactors = FALSE) + tmp_pt <- tmp_pt[!is.na(tmp_pt$y), ] + + # with peakwidth and black stroke if (useWidth) { - # value peakwidth (add color ID to each point) + ## Prepare peakWidth (must go first to be the bottom most layer) tmp_pwidth <- data.frame(x = c(x_axis, x_axis), y = c(widthMin, widthMax), colr = c(sampleIDColour, sampleIDColour), stringsAsFactors = FALSE) - tmp_pwidth <- tmp_pwidth[!is.na(tmp_pwidth$y), ] - p <- p + ggplot2::geom_line(data = tmp_pwidth, - ggplot2::aes(x = x, y = y, group = x, colour=colr), size=1) + tmp_pwidth <- tmp_pwidth[!is.na(tmp_pwidth$y),]#remove val without pkwdt + if (rotateAxis) { #flip x and y + p <- p + ggplot2::geom_line(data=tmp_pwidth, + ggplot2::aes(x=y, y=x, group=x, colour=colr), linewidth=1) + p <- p + ggplot2::geom_point(data = tmp_pt, + ggplot2::aes(x=y, y=x, fill=colr), + colour="black", shape=21, stroke=1, size=2) + } else { + p <- p + ggplot2::geom_line(data = tmp_pwidth, + ggplot2::aes(x=x, y=y, group=x, colour=colr), linewidth=1) + p <- p + ggplot2::geom_point(data = tmp_pt, + ggplot2::aes(x=x, y=y, fill=colr), + colour="black", shape=21, stroke=1, size=2) + } if (verbose) { message("Peakwidth values plotted") } - } - - # apex value - if (useRunOrder) { - p <- p + ggplot2::xlab("Acquisition Time") - #labels are flipped, themes are not - tmp_pt <- data.frame(x = acquTime, y = apexValue, colr = sampleIDColour, - stringsAsFactors = FALSE) - if (verbose) { message("Values plotted by run order") } + # without peakwidth and black stroke } else { - # labels are flipped, themes are not - # add apex point (add the color ID to each point, and an ID pointing to - # the black stroke) - tmp_pt <- data.frame(x = x_axis, y = apexValue, colr = sampleIDColour, - stringsAsFactors = FALSE) - if (verbose) { message("Values plotted by input order") } - } - # add apex points - tmp_pt <- tmp_pt[!is.na(tmp_pt$y), ] - # with black stroke - if (useWidth) { - p <- p + ggplot2::geom_point(data = tmp_pt, - ggplot2::aes(x = x, y = y, fill = colr), colour = "black", - shape = 21, stroke = 1, size = 2) - # without black stroke - } else { - p <- p + ggplot2::geom_point(data = tmp_pt, - ggplot2::aes(x = x, y = y, colour = colr)) + if (rotateAxis) { #flip x and y + p <- p + ggplot2::geom_point(data=tmp_pt, + ggplot2::aes(x=y, y=x, colour=colr)) + } else { + p <- p + ggplot2::geom_point(data = tmp_pt, + ggplot2::aes(x=x, y=y, colour=colr)) + } } - return(p) } -# Rotate axis -plotPeakwidth_rotateAxis <- function(p, rotateAxis, useRunOrder, verbose) { - # rotate axis (labels are carried with the flip, but themes are applied - # afterwards) - if (rotateAxis) { - p <- p + ggplot2::coord_flip() - - if (useRunOrder) { # Run order - # if date axis vertical, put dates in order from top to bottom - # function to reverse date axis - c_trans <- function(a, b, breaks = b$breaks, format = b$format) { - a <- scales::as.trans(a) - b <- scales::as.trans(b) - name <- paste(a$name, b$name, sep = "-") - trans <- function(x) a$trans(b$trans(x)) - inv <- function(x) b$inverse(a$inverse(x)) - scales::trans_new(name = name, transform = trans, inverse = inv, - breaks = breaks, format = format) - } - rev_date <- c_trans("reverse", "time") - - p <- p + ggplot2::theme( - axis.text.y = ggplot2::element_text(angle = 45, hjust = 1)) + - ggplot2::scale_x_continuous(trans = rev_date, - expand = c(0.007, 0.007)) - } else { # no run order - p <- p + ggplot2::theme(axis.title.y = ggplot2::element_blank(), - axis.text.y = ggplot2::element_blank(), - axis.ticks.x = ggplot2::element_blank()) + - ggplot2::scale_x_continuous(breaks = NULL, - expand = c(0.007, 0.007)) - } - if (verbose) { message("x and y axis rotated") } - - } else { # no rotation - if (useRunOrder) { - p <- p + ggplot2::theme( - axis.text.x = ggplot2::element_text(angle = 45, hjust = 1)) + +# Set labels and rotate axis if necessary +plotPeakwidth_rotateAxis_setLabels <- function(p, rotateAxis, useRunOrder, + acquTime, verbose) { + ## Ordering of values and axis labelling + if (useRunOrder) { + if (rotateAxis) { # date axis rotated (+ flipped) + p <- p + coord_y_datetime(ylim = c(max(acquTime), min(acquTime))) + + ggplot2::xlab(varName) + + ggplot2::ylab("Acquisition Time") + + ggplot2::theme( + axis.text.y=ggplot2::element_text(angle=45, hjust=1)) + + ggplot2::scale_y_datetime(expand = c(0.007, 0.007)) + if (verbose) { message("x and y axis rotated") } + } else { # date axis not rotated + p <- p + ggplot2::xlab("Acquisition Time") + + ggplot2::ylab(varName) + + ggplot2::theme( + axis.text.x=ggplot2::element_text(angle=45, hjust=1)) + ggplot2::scale_x_datetime(expand = c(0.007, 0.007)) - } else { - p <- p + ggplot2::theme(axis.title.x = ggplot2::element_blank(), - axis.text.x = ggplot2::element_blank(), - axis.ticks.x = ggplot2::element_blank()) + - ggplot2::scale_x_continuous(breaks = NULL, - expand = c(0.007, 0.007)) + } + } else { + if (rotateAxis) { # input order axis rotated (+ flipped) + suppressMessages( + p <- p + #needs to go first + ggplot2::scale_y_continuous(breaks=NULL, expand=c(0.007,0.007))+ + ggplot2::ylim(max(x_axis), min(x_axis)) + + ggplot2::xlab(varName) + + ggplot2::theme(axis.title.y = ggplot2::element_blank(), + axis.text.y = ggplot2::element_blank(), + axis.ticks.y = ggplot2::element_blank()) + ) + if (verbose) { message("x and y axis rotated") } + } else { # input order axis not rotated + p <- p + ggplot2::ylab(varName) + + ggplot2::theme(axis.title.x = ggplot2::element_blank(), + axis.text.x = ggplot2::element_blank(), + axis.ticks.x = ggplot2::element_blank()) + + ggplot2::scale_x_continuous(breaks=NULL, expand=c(0.007,0.007)) } } return(p) diff --git a/R/plotEICDetectedPeakwidth.R b/R/plotEICDetectedPeakwidth.R index 97bf883..df96406 100644 --- a/R/plotEICDetectedPeakwidth.R +++ b/R/plotEICDetectedPeakwidth.R @@ -57,7 +57,7 @@ plotEICDetectedPeakwidth <- function(ROIDataPointSampleList, cpdID, cpdName, rt, maxX <- max(ggplot2::layer_scales(p_spec)$x$range$range[2], ggplot2::layer_scales(p_peakwidth)$y$range$range[2]) p_spec <- p_spec + ggplot2::xlim(minX, maxX) - p_peakwidth <- p_peakwidth + ggplot2::ylim(minX, maxX) + suppressMessages(p_peakwidth <- p_peakwidth + ggplot2::ylim(minX, maxX)) # convert to gtables p_spec <- ggplot2::ggplot_gtable(ggplot2::ggplot_build(p_spec)) p_peakwidth <- ggplot2::ggplot_gtable(ggplot2::ggplot_build(p_peakwidth)) diff --git a/inst/NEWS b/inst/NEWS index 8d97bfa..3709ad4 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -1,2 +1,4 @@ -Changes in version 1.13.1 (2022-11-06) -- Bugfix: plotHistogram changing warning message \ No newline at end of file +Changes in version 1.13.1 (2022-12-11) +- Bugfix: plotHistogram changing warning message +- Bugfix: peakPantheR_plotPeakwidth issue due to ggplot2 behaviour changes for + date axis \ No newline at end of file diff --git a/tests/testthat/test_annotationDiagnosticMultiplot.R b/tests/testthat/test_annotationDiagnosticMultiplot.R index 00ab387..d1722bb 100644 --- a/tests/testthat/test_annotationDiagnosticMultiplot.R +++ b/tests/testthat/test_annotationDiagnosticMultiplot.R @@ -22,7 +22,7 @@ input_targetFeatTable[2,] <- c("ID-2", "Cpd 2", 3280., 3385.577, 3440., 496.1950 input_targetFeatTable[,c(3:8)] <- sapply(input_targetFeatTable[,c(3:8)], as.numeric) # acquisitionTime -input_acquisitionTime <- c(Sys.time(), Sys.time()+900, Sys.time()+1800) +input_acquisitionTime <- as.POSIXct(c(Sys.time(), Sys.time()+900, Sys.time()+1800)) # peakFit # 1 diff --git a/tests/testthat/test_peakPantheR_plotPeakwidth.R b/tests/testthat/test_peakPantheR_plotPeakwidth.R index 2e2090b..e8e4206 100644 --- a/tests/testthat/test_peakPantheR_plotPeakwidth.R +++ b/tests/testthat/test_peakPantheR_plotPeakwidth.R @@ -46,8 +46,8 @@ test_that('plot 3 samples, no color, rotate axis', { # Check plot properties expect_true(ggplot2::is.ggplot(result_3splNoColRot)) - expect_equal(result_3splNoColRot$labels$x, "x") #after rotations axis still have the previous name - expect_equal(result_3splNoColRot$labels$y, "Test variable 3") + expect_equal(result_3splNoColRot$labels$x, "Test variable 3") + expect_equal(result_3splNoColRot$labels$y, "x") expect_equal(length(result_3splNoColRot), 9) }) @@ -59,8 +59,8 @@ test_that('plot 3 samples, no color, acquisition time, rotate axis', { # Check plot properties expect_true(ggplot2::is.ggplot(result_3splNoColRotRunOrder)) - expect_equal(result_3splNoColRotRunOrder$labels$x, "Acquisition Time") #after rotations axis still have the previous name - expect_equal(result_3splNoColRotRunOrder$labels$y, "Test variable 4") + expect_equal(result_3splNoColRotRunOrder$labels$x, "Test variable 4") + expect_equal(result_3splNoColRotRunOrder$labels$y, "Acquisition Time") expect_equal(length(result_3splNoColRotRunOrder), 9) }) @@ -98,8 +98,8 @@ test_that('plot 4 samples with color, rotate axis', { # Check plot properties expect_true(ggplot2::is.ggplot(result_4splWithColRot)) - expect_equal(result_4splWithColRot$labels$x, "x") #after rotations axis still have the previous name - expect_equal(result_4splWithColRot$labels$y, "Test variable 7") + expect_equal(result_4splWithColRot$labels$x, "Test variable 7") + expect_equal(result_4splWithColRot$labels$y, "x") expect_equal(length(result_4splWithColRot), 9) }) @@ -111,7 +111,7 @@ test_that('plot 4 samples with color, acquisition time, rotate axis', { # Check plot properties expect_true(ggplot2::is.ggplot(result_4splWithColRotRunOrder)) - expect_equal(result_4splWithColRotRunOrder$labels$x, "Acquisition Time") #after rotations axis still have the previous name + expect_equal(result_4splWithColRotRunOrder$labels$x, "Acquisition Time") expect_equal(result_4splWithColRotRunOrder$labels$y, "Test variable 8") expect_equal(length(result_4splWithColRotRunOrder), 9) }) @@ -130,8 +130,8 @@ test_that('sampleColour length warning, peakwidth and rotate and input order mes # Check plot properties expect_true(ggplot2::is.ggplot(result_plotColourWarning$result)) - expect_equal(result_plotColourWarning$result$labels$x, "x") - expect_equal(result_plotColourWarning$result$labels$y, "Test variable 9") + expect_equal(result_plotColourWarning$result$labels$x, "Test variable 9") + expect_equal(result_plotColourWarning$result$labels$y, "x") expect_equal(length(result_plotColourWarning$result), 9) }) From 6c1bf6093b60a7b03e5202621d007884e55ad229 Mon Sep 17 00:00:00 2001 From: "Arnaud M. Wolfer" Date: Sun, 11 Dec 2022 23:46:05 +0100 Subject: [PATCH 4/5] bugfix --- R/peakPantheR_plotPeakwidth.R | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/R/peakPantheR_plotPeakwidth.R b/R/peakPantheR_plotPeakwidth.R index fd94441..b6e5d28 100644 --- a/R/peakPantheR_plotPeakwidth.R +++ b/R/peakPantheR_plotPeakwidth.R @@ -60,11 +60,6 @@ peakPantheR_plotPeakwidth <- function(apexValue, widthMin=NULL, widthMax = NULL, acquTime=NULL, varName="variable", sampleColour = NULL, rotateAxis = FALSE, verbose = TRUE) { - - coord_y_datetime <- function(xlim = NULL, ylim = NULL, expand = TRUE) { - if (!is.null(ylim)) { ylim <- lubridate::as_datetime(ylim) } - ggplot2::coord_cartesian(xlim = xlim, ylim = ylim, expand = expand) - } ## Check input resInp <- plotPeakwidth_checkInput(apexValue, widthMin, widthMax, acquTime, @@ -100,8 +95,8 @@ peakPantheR_plotPeakwidth <- function(apexValue, widthMin=NULL, widthMax = NULL, } ## final ordering and axis labelling - p <- plotPeakwidth_rotateAxis_setLabels <- function(p, rotateAxis, - useRunOrder, acquTime, verbose) + p <- plotPeakwidth_rotateAxis_setLabels(p, rotateAxis, useRunOrder, + x_axis, acquTime, varName, verbose) return(p) } @@ -209,7 +204,11 @@ plotPeakwidth_plotWidthApex <- function(p, useWidth, rotateAxis, } # Set labels and rotate axis if necessary plotPeakwidth_rotateAxis_setLabels <- function(p, rotateAxis, useRunOrder, - acquTime, verbose) { + x_axis, acquTime, varName, verbose) { + coord_y_datetime <- function(xlim = NULL, ylim = NULL, expand = TRUE) { + if (!is.null(ylim)) { ylim <- lubridate::as_datetime(ylim) } + ggplot2::coord_cartesian(xlim = xlim, ylim = ylim, expand = expand) + } ## Ordering of values and axis labelling if (useRunOrder) { if (rotateAxis) { # date axis rotated (+ flipped) From 8929d1b993581809a4f3d644088421f5d12dddd1 Mon Sep 17 00:00:00 2001 From: "Arnaud M. Wolfer" Date: Mon, 12 Dec 2022 00:34:39 +0100 Subject: [PATCH 5/5] ggplot2 depreciation warning --- R/plotHistogram.R | 2 +- R/zzz.R | 2 +- inst/NEWS | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/R/plotHistogram.R b/R/plotHistogram.R index daa50a2..f5bd4c1 100644 --- a/R/plotHistogram.R +++ b/R/plotHistogram.R @@ -19,7 +19,7 @@ plotHistogram <- function(var, varName = "Variable", density = TRUE, ...) { # with density if (density) { p_hist <- p_hist + - ggplot2::geom_histogram(ggplot2::aes(y = ..density..), + ggplot2::geom_histogram(ggplot2::aes(y=ggplot2::after_stat(density)), colour = "black", fill = "white", ...) + ggplot2::geom_density(alpha = 0.1, fill = "blue") # without density diff --git a/R/zzz.R b/R/zzz.R index 65f31b9..f1d29d9 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -6,7 +6,7 @@ utils::globalVariables( # data.frame column names used in ggplot (cannot use aes_string due to # transformations to the column in aes()) - c("x","y","colr","..density..","rt","int","specID", "rt_dev_sec", + c("x","y","colr","rt","int","specID", "rt_dev_sec", "isReference", "predictedRtDrift") ) invisible() diff --git a/inst/NEWS b/inst/NEWS index 3709ad4..65ac3a9 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -1,4 +1,5 @@ Changes in version 1.13.1 (2022-12-11) - Bugfix: plotHistogram changing warning message - Bugfix: peakPantheR_plotPeakwidth issue due to ggplot2 behaviour changes for - date axis \ No newline at end of file + date axis +- Depreciation warning from ggplot2 `..density..` to `after_stat()` \ No newline at end of file