Skip to content

Commit d7d18e8

Browse files
yutannihilationhadley
authored andcommitted
use fortify.grouped_df() instead of ggplot.grouped_df() (#2623)
* use fortify.grouped_df() instead of ggplot.grouped_df() * fix the signature of fortify.grouped_df()
1 parent b0ec7a3 commit d7d18e8

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

NAMESPACE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ S3method(fortify,confint.glht)
3535
S3method(fortify,data.frame)
3636
S3method(fortify,default)
3737
S3method(fortify,glht)
38+
S3method(fortify,grouped_df)
3839
S3method(fortify,lm)
3940
S3method(fortify,map)
4041
S3method(fortify,summary.glht)
4142
S3method(fortify,tbl)
4243
S3method(ggplot,"function")
43-
S3method(ggplot,data.frame)
4444
S3method(ggplot,default)
45-
S3method(ggplot,grouped_df)
4645
S3method(ggplot_add,"NULL")
4746
S3method(ggplot_add,Coord)
4847
S3method(ggplot_add,Facet)

R/fortify.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ fortify.NULL <- function(model, data, ...) waiver()
2020
#' @export
2121
fortify.function <- function(model, data, ...) model
2222
#' @export
23+
fortify.grouped_df <- function(model, data, ...) {
24+
model$.group <- dplyr::group_indices(model)
25+
model
26+
}
27+
#' @export
2328
fortify.default <- function(model, data, ...) {
2429
msg <- paste0(
2530
"`data` must be a data frame, or other object coercible by `fortify()`, ",

R/plot.r

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,12 @@ ggplot <- function(data = NULL, mapping = aes(), ...,
7777
#' @export
7878
ggplot.default <- function(data = NULL, mapping = aes(), ...,
7979
environment = parent.frame()) {
80-
ggplot.data.frame(fortify(data, ...), mapping, environment = environment)
81-
}
82-
83-
#' @export
84-
ggplot.function <- function(data = NULL, mapping = aes(), ...,
85-
environment = parent.frame()) {
86-
# Added to avoid functions end in ggplot.default
87-
stop("You're passing a function as global data.\nHave you misspelled the `data` argument in `ggplot()`", call. = FALSE)
88-
}
89-
90-
#' @export
91-
ggplot.data.frame <- function(data, mapping = aes(), ...,
92-
environment = parent.frame()) {
9380
if (!missing(mapping) && !inherits(mapping, "uneval")) {
9481
stop("Mapping should be created with `aes() or `aes_()`.", call. = FALSE)
9582
}
9683

84+
data <- fortify(data, ...)
85+
9786
p <- structure(list(
9887
data = data,
9988
layers = list(),
@@ -112,11 +101,10 @@ ggplot.data.frame <- function(data, mapping = aes(), ...,
112101
}
113102

114103
#' @export
115-
ggplot.grouped_df <- function(data, mapping = aes(), ...,
116-
environment = parent.frame()) {
117-
118-
data$.group <- dplyr::group_indices(data)
119-
ggplot.data.frame(data, mapping = mapping, ..., environment = environment)
104+
ggplot.function <- function(data = NULL, mapping = aes(), ...,
105+
environment = parent.frame()) {
106+
# Added to avoid functions end in ggplot.default
107+
stop("You're passing a function as global data.\nHave you misspelled the `data` argument in `ggplot()`", call. = FALSE)
120108
}
121109

122110
plot_clone <- function(plot) {

0 commit comments

Comments
 (0)