forked from tidyverse/ggplot2
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement geom_function(). Closes tidyverse#3611.
- Loading branch information
1 parent
8a3f711
commit 9b2db4a
Showing
6 changed files
with
93 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#' @export | ||
#' @rdname stat_function | ||
geom_function <- function(mapping = NULL, data = NULL, stat = "function", | ||
position = "identity", na.rm = FALSE, | ||
show.legend = NA, inherit.aes = TRUE, ...) { | ||
layer( | ||
data = data, | ||
mapping = mapping, | ||
stat = stat, | ||
geom = GeomFunction, | ||
position = position, | ||
show.legend = show.legend, | ||
inherit.aes = inherit.aes, | ||
params = list( | ||
na.rm = na.rm, | ||
... | ||
) | ||
) | ||
} | ||
|
||
#' @rdname ggplot2-ggproto | ||
#' @format NULL | ||
#' @usage NULL | ||
#' @export | ||
#' @include geom-path.r | ||
GeomFunction <- ggproto("GeomFunction", GeomPath, | ||
draw_panel = function(self, data, panel_params, coord, arrow = NULL, | ||
lineend = "butt", linejoin = "round", linemitre = 10, | ||
na.rm = FALSE) { | ||
groups <- unique(data$group) | ||
if (length(groups) > 1) { | ||
warn("Multiple drawing groups in `geom_function()`. Did you use the correct `group`, `colour`, or `fill` aesthetics?") | ||
} | ||
|
||
ggproto_parent(GeomPath, self)$draw_panel( | ||
data, panel_params, coord, arrow, lineend, linejoin, linemitre, na.rm | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.