Description Usage Arguments Details Author(s) See Also Examples
Transform data into a plotly visualization.
1 2 3 4 |
data |
A data frame (optional). |
... |
These arguments are documented at https://plot.ly/r/reference/
Note that acceptable arguments depend on the value of |
type |
A character string describing the type of trace. If |
color |
A formula containing a name or expression.
Values are scaled and mapped to color codes based on the value of
|
colors |
Either a colorbrewer2.org palette name (e.g. "YlOrRd" or "Blues"),
or a vector of colors to interpolate in hexadecimal "#RRGGBB" format,
or a color interpolation function like |
alpha |
A number between 0 and 1 specifying the alpha channel applied to color. |
symbol |
A formula containing a name or expression.
Values are scaled and mapped to symbols based on the value of |
symbols |
A character vector of symbol types. For possible values, see schema. |
size |
A variable name or numeric vector to encode the size of markers. |
sizes |
A numeric vector of length 2 used to scale sizes to pixels. |
linetype |
Either a variable name or a (discrete) vector to use for linetype encoding. |
linetypes |
A character vector of line types. For possible values, see schema. |
width |
Width in pixels (optional, defaults to automatic sizing). |
height |
Height in pixels (optional, defaults to automatic sizing). |
source |
Only relevant for event_data. |
There are a number of "visual properties" that aren't included in the officical Reference section (see below).
Carson Sievert
layout()
, add_trace()
, style()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | ## Not run:
# plot_ly() tries to create a sensible plot based on the information you
# give it. If you don't provide a trace type, plot_ly() will infer one.
plot_ly(economics, x = ~pop)
plot_ly(economics, x = ~date, y = ~pop)
# plot_ly() doesn't require data frame(s), which allows one to take
# advantage of trace type(s) designed specifically for numeric matrices
plot_ly(z = ~volcano)
plot_ly(z = ~volcano, type = "surface")
# plotly has a functional interface: every plotly function takes a plotly
# object as it's first input argument and returns a modified plotly object
add_lines(plot_ly(economics, x = ~date, y = ~unemploy/pop))
# To make code more readable, plotly imports the pipe operator from magrittr
economics %>% plot_ly(x = ~date, y = ~unemploy/pop) %>% add_lines()
# Attributes defined via plot_ly() set 'global' attributes that
# are carried onto subsequent traces
plot_ly(economics, x = ~date, line = list(color = "black")) %>%
add_trace(y = ~uempmed, mode = "markers+lines") %>%
add_lines(y = ~psavert) %>%
layout(title = "Setting global trace attributes")
# Attributes are documented in the figure reference -> https://plot.ly/r/reference
# You might notice plot_ly() has named arguments that aren't in the figure
# reference. These arguments make it easier to map abstract data values to
# visual attributes.
p <- plot_ly(iris, x = ~Sepal.Width, y = ~Sepal.Length)
add_markers(p, color = ~Petal.Length, size = ~Petal.Length)
add_markers(p, color = ~Species)
add_markers(p, color = ~Species, colors = "Set1")
add_markers(p, symbol = ~Species)
add_paths(p, linetype = ~Species)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.