Skip to content

Commit

Permalink
make gp_plot more generic, document
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiAragaki committed Aug 30, 2024
1 parent ca8f62e commit 7d5c893
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Imports:
cli,
dplyr,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

S3method(as_gp,default)
S3method(as_gp,list)
S3method(gp_plot,data.frame)
S3method(gp_plot,gp)
S3method(gp_sec,gp)
S3method(print,gp)
S3method(well_data,gp)
Expand Down
25 changes: 21 additions & 4 deletions R/gp_plot.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' Plot a `gp` object
#'
#' @param gp A `gp` object
#' @param name Symbol. Name of a column in `gp$well_data` to use as a color.
#' @param x A `gp` object or `data.frame`
#' @param name Symbol. Name of a column in `gp$well_data` (or a column in the
#' data.frame if data.frame was supplied) to use as a color.
#' @param ... Additional arguments to be passed to `ggplot2::geom_point()`
#'
#' @return a `ggplot`
Expand All @@ -10,15 +11,31 @@
#' @examples
#'
#' gp(16, 24) |> gp_plot(.row)
gp_plot <- function(gp, name = .sec, ...) {
gp_plot <- function(x, name = .sec, ...) {
UseMethod("gp_plot")
}

#' @rdname gp_plot
#' @export
gp_plot.gp <- function(x, name = .sec, ...) {
dots <- rlang::dots_list(..., size = 4, .homonyms = "first")

wd <- gp$well_data
wd <- x$well_data
ggplot2::ggplot(wd, ggplot2::aes(x = .col, y = .row, color = {{ name }})) +
ggplot2::geom_point(...) +
ggplot2::scale_y_reverse()
}

#' @rdname gp_plot
#' @export
gp_plot.data.frame <- function(x, name = .sec, ...) {
dots <- rlang::dots_list(..., size = 4, .homonyms = "first")

ggplot2::ggplot(x, ggplot2::aes(x = .col, y = .row, color = {{ name }})) +
ggplot2::geom_point(...) +
ggplot2::scale_y_reverse()
}

#' A theme for making little in-line plots
#'
#' @return A `ggplot2` theme
Expand Down
13 changes: 10 additions & 3 deletions man/gp_plot.Rd

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

0 comments on commit 7d5c893

Please sign in to comment.