Permalink
Browse files

Fix bugs in geom_rangeframe

Fixes bugs in geom_rangeframe due to new ggplot2 version. Closes issue #70.
  • Loading branch information...
jrnold committed Oct 11, 2016
1 parent 314ec6f commit 2c294bf86550799ad90ccf948bf367db836ddc1f
Showing with 73 additions and 65 deletions.
  1. +2 −1 NEWS
  2. +64 −57 R/geom-rangeframe.R
  3. +7 −7 man/geom_rangeframe.Rd
View
3 NEWS
@@ -2,7 +2,8 @@ ggthemes 3.3.0
------------------------
* Update themes to changes in ggplot 2.1.0.9000. Thanks @juliasilge (#71)
-* `tufte_boxplot` uses `position="dodge"`. Thanks @jgellar (#68)
+* `tufte_boxplot` uses `position="dodge"` by default. Thanks @jgellar (#68)
+* Bugfix: Fix errors in `geom_rangeframe` in new version of ggplot2. Thanks @coulmont (#70)
ggthemes 3.2.0
------------------------
View
@@ -26,10 +26,15 @@
#' geom_point() +
#' geom_rangeframe() +
#' theme_tufte()
-geom_rangeframe <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", sides = "bl",
- na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...) {
+geom_rangeframe <- function(mapping = NULL,
+ data = NULL,
+ stat = "identity",
+ position = "identity",
+ ...,
+ sides = "bl",
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
@@ -39,68 +44,70 @@ geom_rangeframe <- function(mapping = NULL, data = NULL, stat = "identity",
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
- params = list(sides = sides,
- na.rm = na.rm,
- ...)
+ params = list(
+ sides = sides,
+ na.rm = na.rm,
+ ...
+ )
)
}
#' @rdname geom_rangeframe
#' @usage NULL
#' @format NULL
#' @export
-GeomRangeFrame <-
- ggproto("GeomRangeFrame", Geom,
- draw_panel = function(data, panel_scales, coord, sides = "bl") {
- rugs <- list()
- data <- coord$transform(data, panel_scales)
+GeomRangeFrame <- ggproto("GeomRangeFrame", Geom,
+ optional_aes = c("x", "y"),
- gp <- gpar(col = alpha(data$colour, data$alpha),
- lty = data$linetype,
- lwd = data$size * .pt)
- if (!is.null(data$x)) {
- if (grepl("b", sides)) {
- rugs$x_b <-
- segmentsGrob(x0 = unit(min(data$x), "native"),
- x1 = unit(max(data$x), "native"),
- y0 = unit(0, "npc"),
- y1 = unit(0, "npc"),
- gp = gp)
- }
+ draw_panel = function(data, panel_scales, coord, sides = "bl") {
+ rugs <- list()
+ data <- coord[["transform"]](data, panel_scales)
+ gp <- gpar(col = alpha(data[["colour"]], data[["alpha"]]),
+ lty = data[["linetype"]],
+ lwd = data[["size"]] * .pt)
+ if (!is.null(data[["x"]])) {
+ if (grepl("b", sides)) {
+ rugs[["x_b"]] <-
+ segmentsGrob(x0 = unit(min(data[["x"]]), "native"),
+ x1 = unit(max(data[["x"]]), "native"),
+ y0 = unit(0, "npc"),
+ y1 = unit(0, "npc"),
+ gp = gp)
+ }
- if (grepl("t", sides)) {
- rugs$x_t <-
- segmentsGrob(x0 = unit(min(data$x), "native"),
- x1 = unit(max(data$x), "native"),
- y0 = unit(1, "npc"),
- y1 = unit(1, "npc"),
- gp = gp)
- }
- }
+ if (grepl("t", sides)) {
+ rugs[["x_t"]] <-
+ segmentsGrob(x0 = unit(min(data[["x"]]), "native"),
+ x1 = unit(max(data[["x"]]), "native"),
+ y0 = unit(1, "npc"),
+ y1 = unit(1, "npc"),
+ gp = gp)
+ }
+ }
- if (!is.null(data$y)) {
- if (grepl("l", sides)) {
- rugs$y_l <-
- segmentsGrob(y0 = unit(min(data$y), "native"),
- y1 = unit(max(data$y), "native"),
- x0 = unit(0, "npc"),
- x1 = unit(0, "npc"),
- gp = gp)
- }
+ if (!is.null(data[["y"]])) {
+ if (grepl("l", sides)) {
+ rugs[["y_l"]] <-
+ segmentsGrob(y0 = unit(min(data[["y"]]), "native"),
+ y1 = unit(max(data[["y"]]), "native"),
+ x0 = unit(0, "npc"),
+ x1 = unit(0, "npc"),
+ gp = gp)
+ }
- if (grepl("r", sides)) {
- rugs$y_r <-
- segmentsGrob(y0 = unit(min(data$y), "native"),
- y1 = unit(max(data$y), "native"),
- x0 = unit(1, "npc"),
- x1 = unit(1, "npc"),
- gp = gp)
- }
- }
- gTree(children = do.call("gList", rugs))
- },
+ if (grepl("r", sides)) {
+ rugs[["y_r"]] <-
+ segmentsGrob(y0 = unit(min(data[["y"]]), "native"),
+ y1 = unit(max(data[["y"]]), "native"),
+ x0 = unit(1, "npc"),
+ x1 = unit(1, "npc"),
+ gp = gp)
+ }
+ }
+ gTree(children = do.call("gList", rugs))
+ },
+ default_aes = aes(colour = "black", size = 0.5,
+ linetype = 1, alpha = NA),
- default_aes = aes(colour = "black", size = 0.5,
- linetype = 1, alpha = NA),
- draw_legend = draw_key_path
- )
+ draw_key = draw_key_path
+)
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 2c294bf

Please sign in to comment.