Skip to content

Commit

Permalink
update doc for ggplotly to include standard arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
gdmcdonald committed Aug 4, 2022
1 parent 88a4ae1 commit 1eef773
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: notly
Title: Reversible ggplot to plotly conversion
Version: 0.0.0.9000
Version: 0.1
Authors@R: c(
person("Gordon", "McDonald", ,"gordon.mcdonald@sydney.edu.au", role = c("aut", "cre")),
person("Henry", "Lydecker", ,"henry.lydecker@gmail.com", role = c("aut"))
Expand Down
68 changes: 63 additions & 5 deletions R/notly.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,71 @@
#' Turn a ggplot into a plotly object
#' Convert ggplot2 to notly (plotly with embedded ggplot)
#'
#' This function takes a ggplot object and turns it into a plotly object.
#' The original ggplot object is retained inside of the new plotly object.
#' This function converts a [ggplot2::ggplot()] object to a
#' notly object. The original ggplot object is retained inside of the new plotly object.
#' This makes this conversion reversible, allowing you to freely go back and forth betweeen ggplot and plotly.
#'
#' @param p ggplot object
#' @details Conversion of relative sizes depends on the size of the current
#' graphics device (if no device is open, width/height of a new (off-screen)
#' device defaults to 640/480). In other words, `height` and
#' `width` must be specified at runtime to ensure sizing is correct.
#' For examples on how to specify the output container's `height`/`width` in a
#' shiny app, see `plotly_example("shiny", "ggplotly_sizing")`.
#'
#' @param p a ggplot object.
#' @param width Width of the plot in pixels (optional, defaults to automatic sizing).
#' @param height Height of the plot in pixels (optional, defaults to automatic sizing).
#' @param tooltip a character vector specifying which aesthetic mappings to show
#' in the tooltip. The default, "all", means show all the aesthetic mappings
#' (including the unofficial "text" aesthetic). The order of variables here will
#' also control the order they appear. For example, use
#' `tooltip = c("y", "x", "colour")` if you want y first, x second, and
#' colour last.
#' @param dynamicTicks should plotly.js dynamically generate axis tick labels?
#' Dynamic ticks are useful for updating ticks in response to zoom/pan
#' interactions; however, they can not always reproduce labels as they
#' would appear in the static ggplot2 image.
#' @param layerData data from which layer should be returned?
#' @param originalData should the "original" or "scaled" data be returned?
#' @param source a character string of length 1. Match the value of this string
#' with the source argument in [event_data()] to retrieve the
#' event data corresponding to a specific plot (shiny apps can have multiple plots).
#' @param ... arguments passed onto methods.
#' @return Plotly object with a ggplot nested inside
#' @export

#' @author Carson Sievert
#' @references \url{https://plotly.com/ggplot2/}
#' @seealso [plot_ly()]
#' @examples \dontrun{
#' # simple example
#' ggpenguins <- qplot(bill_length_mm , body_mass_g,
#' data = palmerpenguins::penguins, color = species)
#' ggplotly(ggpenguins)
#'
#' data(canada.cities, package = "maps")
#' viz <- ggplot(canada.cities, aes(long, lat)) +
#' borders(regions = "canada") +
#' coord_equal() +
#' geom_point(aes(text = name, size = pop), colour = "red", alpha = 1/2)
#' ggplotly(viz, tooltip = c("text", "size"))
#'
#' # linked scatterplot brushing
#' d <- highlight_key(mtcars)
#' qplot(data = d, x = mpg, y = wt) %>%
#' subplot(qplot(data = d, x = mpg, y = vs)) %>%
#' layout(title = "Click and drag to select points") %>%
#' highlight("plotly_selected")
#'
#'
#' # more brushing (i.e. highlighting) examples
#' demo("crosstalk-highlight-ggplotly", package = "plotly")
#'
#' # client-side linked brushing in a scatterplot matrix
#' highlight_key(palmerpenguins::penguins) %>%
#' GGally::ggpairs(aes(colour = Species), columns = 1:4) %>%
#' ggplotly(tooltip = c("x", "y", "colour")) %>%
#' highlight("plotly_selected")
#' }
#'
ggplotly <- function(
p = ggplot2::last_plot(),
width = NULL,
Expand Down
84 changes: 80 additions & 4 deletions man/ggplotly.Rd

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

0 comments on commit 1eef773

Please sign in to comment.