1- # ' Initiate a plotly visualization
2- # '
3- # ' This function maps R objects to [plotly.js](https://plot.ly/javascript/),
4- # ' an (MIT licensed) web-based interactive charting library. It provides
5- # ' abstractions for doing common things (e.g. mapping data values to
6- # ' fill colors (via `color`) or creating [animation]s (via `frame`)) and sets
7- # ' some different defaults to make the interface feel more 'R-like'
8- # ' (i.e., closer to [plot()] and [ggplot2::qplot()]).
9- # '
10- # ' @details Unless `type` is specified, this function just initiates a plotly
11- # ' object with 'global' attributes that are passed onto downstream uses of
12- # ' [add_trace()] (or similar). A [formula] must always be used when
13- # ' referencing column name(s) in `data` (e.g. `plot_ly(mtcars, x=~wt)`).
14- # ' Formulas are optional when supplying values directly, but they do
15- # ' help inform default axis/scale titles
16- # ' (e.g., `plot_ly(x=mtcars$wt)` vs `plot_ly(x=~mtcars$wt)`)
17- # '
18- # ' @param data A data frame (optional) or [crosstalk::SharedData] object.
19- # ' @param ... Arguments (i.e., attributes) passed along to the trace `type`.
20- # ' See [schema()] for a list of acceptable attributes for a given trace `type`
21- # ' (by going to `traces` -> `type` -> `attributes`). Note that attributes
22- # ' provided at this level may override other arguments
23- # ' (e.g. `plot_ly(x=1:10, y=1:10, color=I("red"), marker=list(color="blue"))`).
24- # ' @param type A character string specifying the trace type
25- # ' (e.g. `"scatter"`, `"bar"`, `"box"`, etc).
26- # ' If specified, it *always* creates a trace, otherwise
27- # ' @param name Values mapped to the trace's name attribute. Since a trace can
28- # ' only have one name, this argument acts very much like `split` in that it
29- # ' creates one trace for every unique value.
30- # ' @param color Values mapped to relevant 'fill-color' attribute(s)
31- # ' (e.g. [fillcolor](https://plot.ly/r/reference#scatter-fillcolor),
32- # ' [marker.color](https://plot.ly/r/reference#scatter-marker-color),
33- # ' [textfont.color](https://plot.ly/r/reference/#scatter-textfont-color), etc.).
34- # ' The mapping from data values to color codes may be controlled using
35- # ' `colors` and `alpha`, or avoided altogether via [I()]
36- # ' (e.g., `color=I("red")`).
37- # ' Any color understood by [grDevices::col2rgb()] may be used in this way.
38- # ' @param colors Either a colorbrewer2.org palette name
39- # ' (e.g. "YlOrRd" or "Blues"),
40- # ' or a vector of colors to interpolate in hexadecimal "#RRGGBB" format,
41- # ' or a color interpolation function like `colorRamp()`.
42- # ' @param stroke Similar to `color`, but values are mapped to relevant 'stroke-color' attribute(s)
43- # ' (e.g., [marker.line.color](https://plot.ly/r/reference#scatter-marker-line-color)
44- # ' and [line.color](https://plot.ly/r/reference#scatter-line-color)
45- # ' for filled polygons). If not specified, `stroke` inherits from `color`.
46- # ' @param strokes Similar to `colors`, but controls the `stroke` mapping.
47- # ' @param alpha A number between 0 and 1 specifying the alpha channel applied to `color`.
48- # ' Defaults to 0.5 when mapping to [fillcolor](https://plot.ly/r/reference#scatter-fillcolor) and 1 otherwise.
49- # ' @param alpha_stroke Similar to `alpha`, but applied to `stroke`.
50- # ' @param symbol (Discrete) values mapped to [marker.symbol](https://plot.ly/r/reference#scatter-marker-symbol).
51- # ' The mapping from data values to symbols may be controlled using
52- # ' `symbols`, or avoided altogether via [I()] (e.g., `symbol=I("pentagon")`).
53- # ' Any [pch] value or [symbol name](https://plot.ly/r/reference#scatter-marker-symbol) may be used in this way.
54- # ' @param symbols A character vector of [pch] values or [symbol names](https://plot.ly/r/reference#scatter-marker-symbol).
55- # ' @param linetype (Discrete) values mapped to [line.dash](https://plot.ly/r/reference#scatter-line-dash).
56- # ' The mapping from data values to symbols may be controlled using
57- # ' `linetypes`, or avoided altogether via [I()] (e.g., `linetype=I("dash")`).
58- # ' Any `lty` (see [par]) value or [dash name](https://plot.ly/r/reference#scatter-line-dash) may be used in this way.
59- # ' @param linetypes A character vector of `lty` values or [dash names](https://plot.ly/r/reference#scatter-line-dash)
60- # ' @param size (Numeric) values mapped to relevant 'fill-size' attribute(s)
61- # ' (e.g., [marker.size](https://plot.ly/r/reference#scatter-marker-size),
62- # ' [textfont.size](https://plot.ly/r/reference#scatter-textfont-size),
63- # ' and [error_x.width](https://plot.ly/r/reference#scatter-error_x-width)).
64- # ' The mapping from data values to symbols may be controlled using
65- # ' `sizes`, or avoided altogether via [I()] (e.g., `size=I(30)`).
66- # ' @param sizes A numeric vector of length 2 used to scale `size` to pixels.
67- # ' @param span (Numeric) values mapped to relevant 'stroke-size' attribute(s)
68- # ' (e.g.,
69- # ' [marker.line.width](https://plot.ly/r/reference#scatter-marker-line-width),
70- # ' [line.width](https://plot.ly/r/reference#scatter-line-width) for filled polygons,
71- # ' and [error_x.thickness](https://plot.ly/r/reference#scatter-error_x-thickness))
72- # ' The mapping from data values to symbols may be controlled using
73- # ' `spans`, or avoided altogether via [I()] (e.g., `span=I(30)`).
74- # ' @param spans A numeric vector of length 2 used to scale `span` to pixels.
75- # ' @param split (Discrete) values used to create multiple traces (one trace per value).
76- # ' @param frame (Discrete) values used to create animation frames.
77- # ' @param width Width in pixels (optional, defaults to automatic sizing).
78- # ' @param height Height in pixels (optional, defaults to automatic sizing).
79- # ' @param source a character string of length 1. Match the value of this string
80- # ' with the source argument in [event_data()] to retrieve the
81- # ' event data corresponding to a specific plot (shiny apps can have multiple plots).
82- # ' @author Carson Sievert
83- # ' @references <https://plotly-r.com/overview.html>
84- # ' @seealso \itemize{
85- # ' \item For initializing a plotly-geo object: [plot_geo()]
86- # ' \item For initializing a plotly-mapbox object: [plot_mapbox()]
87- # ' \item For translating a ggplot2 object to a plotly object: [ggplotly()]
88- # ' \item For modifying any plotly object: [layout()], [add_trace()], [style()]
89- # ' \item For linked brushing: [highlight()]
90- # ' \item For arranging multiple plots: [subplot()], [crosstalk::bscols()]
91- # ' \item For inspecting plotly objects: [plotly_json()]
92- # ' \item For quick, accurate, and searchable plotly.js reference: [schema()]
93- # ' }
94- # '
95- # ' @return A plotly
96- # '
97- # ' @importFrom plotly plot_ly
98- # '
99- # ' @export
100- # ' @examples
1+ # ' @name plotly
2+ # ' @rdname plotly
3+ # ' @inherit plotly::plot_ly
4+ # ' @return `plotly`
1015# '
102- # ' # Plotly better not run
103- # ' print("See below examples")
6+ # ' @examples
7+ # ' # TODO
1048# '
105- # ' \dontrun{
106- # ' # plot_ly() tries to create a sensible plot based on the information you
107- # ' # give it. If you don't provide a trace type, plot_ly() will infer one.
108- # ' plot_ly(economics, x=~pop)
109- # ' plot_ly(economics, x=~date, y=~pop)
110- # ' # plot_ly() doesn't require data frame(s), which allows one to take
111- # ' # advantage of trace type(s) designed specifically for numeric matrices
112- # ' plot_ly(z=~volcano)
113- # ' plot_ly(z=~volcano, type="surface")
114- # '
115- # ' # plotly has a functional interface: every plotly function takes a plotly
116- # ' # object as it's first input argument and returns a modified plotly object
117- # ' add_lines(plot_ly(economics, x=~date, y=~ unemploy / pop))
118- # '
119- # ' # To make code more readable, plotly imports the pipe operator from magrittr
120- # ' economics %>%
121- # ' plot_ly(x=~date, y=~ unemploy / pop) %>%
122- # ' add_lines()
123- # '
124- # ' # Attributes defined via plot_ly() set 'global' attributes that
125- # ' # are carried onto subsequent traces, but those may be over-written
126- # ' plot_ly(economics, x=~date, color=I("black")) %>%
127- # ' add_lines(y=~uempmed) %>%
128- # ' add_lines(y=~psavert, color=I("red"))
129- # '
130- # ' # Attributes are documented in the figure reference -> https://plot.ly/r/reference
131- # ' # You might notice plot_ly() has named arguments that aren't in this figure
132- # ' # reference. These arguments make it easier to map abstract data values to
133- # ' # visual attributes.
134- # ' p <- plot_ly(iris, x=~Sepal.Width, y=~Sepal.Length)
135- # ' add_markers(p, color=~Petal.Length, size=~Petal.Length)
136- # ' add_markers(p, color=~Species)
137- # ' add_markers(p, color=~Species, colors="Set1")
138- # ' add_markers(p, symbol=~Species)
139- # ' add_paths(p, linetype=~Species)
140- # ' }
141- # '
9+ # ' @importFrom plotly plot_ly
10+ # ' @export
14211plot_ly <- function (data = data.frame (), ... , type = NULL , name = NULL ,
14312 color = NULL , colors = NULL , alpha = NULL ,
14413 stroke = NULL , strokes = NULL , alpha_stroke = 1 ,
@@ -151,8 +20,8 @@ plot_ly <- function(data=data.frame(), ..., type=NULL, name=NULL,
15120 UseMethod(" plot_ly" )
15221}
15322
23+ # ' @rdname plotly
15424# ' @export
155- # '
15625plot_ly.tbl_df <- function (data = data.frame (), ... , type = NULL , name = NULL ,
15726 color = NULL , colors = NULL , alpha = NULL ,
15827 stroke = NULL , strokes = NULL , alpha_stroke = 1 ,
@@ -179,6 +48,7 @@ plot_ly.tbl_df <- function(data=data.frame(), ..., type=NULL, name=NULL,
17948 )
18049}
18150
51+ # ' @rdname plotly
18252# ' @export
18353plot_ly.SummarizedExperiment <- function (data = data.frame (), ... , type = NULL , name = NULL ,
18454 color = NULL , colors = NULL , alpha = NULL ,
0 commit comments