Skip to content

Commit

Permalink
Fix bugs in geom_rangeframe
Browse files Browse the repository at this point in the history
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 2c294bf
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 65 deletions.
3 changes: 2 additions & 1 deletion NEWS
Expand Up @@ -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
------------------------
Expand Down
121 changes: 64 additions & 57 deletions R/geom-rangeframe.R
Expand Up @@ -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,
Expand All @@ -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
)
14 changes: 7 additions & 7 deletions man/geom_rangeframe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2c294bf

Please sign in to comment.