diff --git a/DESCRIPTION b/DESCRIPTION index da21a91..6aebce4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ URL: https://r-quantities.github.io/errors/, https://github.com/r-quantities/err BugReports: https://github.com/r-quantities/errors/issues LazyData: true Depends: R (>= 3.0.0) -Suggests: dplyr (>= 1.0.0), vctrs (>= 0.5.0), pillar, ggplot2 (>= 3.4.0), +Suggests: dplyr (>= 1.0.0), vctrs (>= 0.5.0), pillar, ggplot2 (>= 3.5.0), testthat, vdiffr, knitr, rmarkdown RoxygenNote: 7.3.2 Roxygen: list(old_usage = TRUE) diff --git a/NEWS.md b/NEWS.md index 08fe46e..7b51b3e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # errors devel - Improve `cbind` arg name deparsing. +- Switch from `geom_errobarh()` (deprecated) to `geom_errorbar()` with flipped + aesthetics in `geom_errors()` (#63). # errors 0.4.3 diff --git a/R/geom_errors.R b/R/geom_errors.R index 1e9609a..e1bdde1 100644 --- a/R/geom_errors.R +++ b/R/geom_errors.R @@ -104,9 +104,11 @@ MakeGeomErrors <- function() ggplot2::ggproto( data$xmax_bars <- data$xmax data$ymin <- data$ymax <- NULL + params$flipped_aes <- TRUE + params$width <- params$height data$xmin <- data$xmin_errors data$xmax <- data$xmax_errors - data <- ggplot2::GeomErrorbarh$setup_data(data, params) + data <- ggplot2::GeomErrorbar$setup_data(data, params) data$ymin_bars <- data$ymin data$ymax_bars <- data$ymax data$xmin <- data$xmax <- NULL @@ -137,8 +139,8 @@ MakeGeomErrors <- function() ggplot2::ggproto( data$xmax <- data$xmax_errors data$ymin <- data$ymin_bars data$ymax <- data$ymax_bars - grob <- append(grob, list(ggplot2::GeomErrorbarh$draw_panel( - data, panel_params, coord=coord, height=height))) + grob <- append(grob, list(ggplot2::GeomErrorbar$draw_panel( + data, panel_params, coord=coord, width=height, flipped_aes = TRUE))) } grob <- do.call(grid::grobTree, grob) grob$name <- grid::grobName(grob, "geom_errors") diff --git a/tests/testthat/test-plot.R b/tests/testthat/test-plot.R index edb7f7b..354cbdf 100644 --- a/tests/testthat/test-plot.R +++ b/tests/testthat/test-plot.R @@ -27,10 +27,11 @@ test_that("ggplot2 plots work as expected", suppressWarnings({ iris.e[1:4] <- lapply(iris.e[1:4], function(x) set_errors(x, x*0.02)) p0 <- ggplot(iris.e) + aes(Sepal.Length, Sepal.Width, color=Species) + - geom_point() + theme_bw() + theme(legend.position=c(0.6, 0.8)) + geom_point() + theme_bw() + + theme(legend.position="inside", legend.position.inside=c(0.6, 0.8)) p1 <- p0 + geom_errorbar(aes(ymin=errors_min(Sepal.Width), ymax=errors_max(Sepal.Width))) + - geom_errorbarh(aes(xmin=errors_min(Sepal.Length), xmax=errors_max(Sepal.Length))) + geom_errorbar(aes(xmin=errors_min(Sepal.Length), xmax=errors_max(Sepal.Length))) p2 <- p0 + geom_errors() p3 <- p0 + geom_errors(aes(x=drop_errors(Sepal.Length))) p4 <- p0 + geom_errors(aes(y=drop_errors(Sepal.Width))) diff --git a/vignettes/rjournal.Rmd b/vignettes/rjournal.Rmd index 55c126f..190bd68 100644 --- a/vignettes/rjournal.Rmd +++ b/vignettes/rjournal.Rmd @@ -246,7 +246,8 @@ legend(6.2, 4.4, unique(iris.e[["Species"]]), library(ggplot2) ggplot(iris.e) + aes(Sepal.Length, Sepal.Width, color=Species) + - geom_point() + geom_errors() + theme_bw() + theme(legend.position=c(0.6, 0.8)) + geom_point() + geom_errors() + theme_bw() + + theme(legend.position="inside", legend.position.inside=c(0.6, 0.8)) ``` ```{r plot, echo=FALSE, out.width='100%', fig.height=3.5, fig.width=10, fig.cap=paste0(label("fig:plot"), "Base plot with error bars (left) and ggplot2's version (right).")} @@ -259,7 +260,8 @@ legend(6.2, 4.4, unique(iris.e[["Species"]]), library(ggplot2) p <- ggplot(iris.e) + aes(Sepal.Length, Sepal.Width, color=Species) + - geom_point() + geom_errors() + theme_bw() + theme(legend.position=c(0.6, 0.8)) + geom_point() + geom_errors() + theme_bw() + + theme(legend.position="inside", legend.position.inside=c(0.6, 0.8)) plot.new() fig <- par("fig")