Skip to content

Commit 1eef773

Browse files
committed
update doc for ggplotly to include standard arguments
1 parent 88a4ae1 commit 1eef773

File tree

3 files changed

+144
-10
lines changed

3 files changed

+144
-10
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: notly
22
Title: Reversible ggplot to plotly conversion
3-
Version: 0.0.0.9000
3+
Version: 0.1
44
Authors@R: c(
55
person("Gordon", "McDonald", ,"gordon.mcdonald@sydney.edu.au", role = c("aut", "cre")),
66
person("Henry", "Lydecker", ,"henry.lydecker@gmail.com", role = c("aut"))

R/notly.R

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,71 @@
1-
#' Turn a ggplot into a plotly object
1+
#' Convert ggplot2 to notly (plotly with embedded ggplot)
22
#'
3-
#' This function takes a ggplot object and turns it into a plotly object.
4-
#' The original ggplot object is retained inside of the new plotly object.
3+
#' This function converts a [ggplot2::ggplot()] object to a
4+
#' notly object. The original ggplot object is retained inside of the new plotly object.
55
#' This makes this conversion reversible, allowing you to freely go back and forth betweeen ggplot and plotly.
66
#'
7-
#' @param p ggplot object
7+
#' @details Conversion of relative sizes depends on the size of the current
8+
#' graphics device (if no device is open, width/height of a new (off-screen)
9+
#' device defaults to 640/480). In other words, `height` and
10+
#' `width` must be specified at runtime to ensure sizing is correct.
11+
#' For examples on how to specify the output container's `height`/`width` in a
12+
#' shiny app, see `plotly_example("shiny", "ggplotly_sizing")`.
13+
#'
14+
#' @param p a ggplot object.
15+
#' @param width Width of the plot in pixels (optional, defaults to automatic sizing).
16+
#' @param height Height of the plot in pixels (optional, defaults to automatic sizing).
17+
#' @param tooltip a character vector specifying which aesthetic mappings to show
18+
#' in the tooltip. The default, "all", means show all the aesthetic mappings
19+
#' (including the unofficial "text" aesthetic). The order of variables here will
20+
#' also control the order they appear. For example, use
21+
#' `tooltip = c("y", "x", "colour")` if you want y first, x second, and
22+
#' colour last.
23+
#' @param dynamicTicks should plotly.js dynamically generate axis tick labels?
24+
#' Dynamic ticks are useful for updating ticks in response to zoom/pan
25+
#' interactions; however, they can not always reproduce labels as they
26+
#' would appear in the static ggplot2 image.
27+
#' @param layerData data from which layer should be returned?
28+
#' @param originalData should the "original" or "scaled" data be returned?
29+
#' @param source a character string of length 1. Match the value of this string
30+
#' with the source argument in [event_data()] to retrieve the
31+
#' event data corresponding to a specific plot (shiny apps can have multiple plots).
32+
#' @param ... arguments passed onto methods.
833
#' @return Plotly object with a ggplot nested inside
934
#' @export
10-
35+
#' @author Carson Sievert
36+
#' @references \url{https://plotly.com/ggplot2/}
37+
#' @seealso [plot_ly()]
38+
#' @examples \dontrun{
39+
#' # simple example
40+
#' ggpenguins <- qplot(bill_length_mm , body_mass_g,
41+
#' data = palmerpenguins::penguins, color = species)
42+
#' ggplotly(ggpenguins)
43+
#'
44+
#' data(canada.cities, package = "maps")
45+
#' viz <- ggplot(canada.cities, aes(long, lat)) +
46+
#' borders(regions = "canada") +
47+
#' coord_equal() +
48+
#' geom_point(aes(text = name, size = pop), colour = "red", alpha = 1/2)
49+
#' ggplotly(viz, tooltip = c("text", "size"))
50+
#'
51+
#' # linked scatterplot brushing
52+
#' d <- highlight_key(mtcars)
53+
#' qplot(data = d, x = mpg, y = wt) %>%
54+
#' subplot(qplot(data = d, x = mpg, y = vs)) %>%
55+
#' layout(title = "Click and drag to select points") %>%
56+
#' highlight("plotly_selected")
57+
#'
58+
#'
59+
#' # more brushing (i.e. highlighting) examples
60+
#' demo("crosstalk-highlight-ggplotly", package = "plotly")
61+
#'
62+
#' # client-side linked brushing in a scatterplot matrix
63+
#' highlight_key(palmerpenguins::penguins) %>%
64+
#' GGally::ggpairs(aes(colour = Species), columns = 1:4) %>%
65+
#' ggplotly(tooltip = c("x", "y", "colour")) %>%
66+
#' highlight("plotly_selected")
67+
#' }
68+
#'
1169
ggplotly <- function(
1270
p = ggplot2::last_plot(),
1371
width = NULL,

man/ggplotly.Rd

Lines changed: 80 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)