Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 5 additions & 3 deletions R/geom_errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
6 changes: 4 additions & 2 deletions vignettes/rjournal.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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).")}
Expand All @@ -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")
Expand Down