FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
plotly.R/man/plot_ly.Rd at master · plotly/plotly.R · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
plotly
/
plotly.R
Public
Notifications
You must be signed in to change notification settings
Fork
641
Star
2.7k
Code
Issues
714
Pull requests
46
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
plotly.R
/
man
/
plot_ly.Rd
Copy path
More file actions
More file actions
Latest commit
History
History
History
193 lines (165 loc) · 9.17 KB
Breadcrumbs
plotly.R
/
man
/
plot_ly.Rd
Copy path
File metadata and controls
193 lines (165 loc) · 9.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
%
Generated
by
roxygen2
:
do
not
edit
by
hand
%
Please
edit
documentation
in
R
/
plotly.R
\
name
{
plot_ly
}
\
alias
{
plot_ly
}
\
title
{
Initiate
a
plotly
visualization
}
\
usage
{
plot_ly(
data
=
data.frame
(),
...
,
type
=
NULL
,
name
,
color
,
colors
=
NULL
,
alpha
=
NULL
,
stroke
,
strokes
=
NULL
,
alpha_stroke
=
1
,
size
,
sizes
=
c(
10
,
100
),
span
,
spans
=
c(
1
,
20
),
symbol
,
symbols
=
NULL
,
linetype
,
linetypes
=
NULL
,
split
,
frame
,
width
=
NULL
,
height
=
NULL
,
source
=
"
A
"
)
}
\
arguments
{
\
item
{
data
}{
A
data
frame (
optional
)
or
\
link
[
crosstalk
:
SharedData
]{
crosstalk
::
SharedData
}
object.
}
\
item
{
...
}{Arguments (
i.e.
,
attributes
)
passed
along
to
the
trace
\
code
{
type
}
.
See
\
code
{\
link
[
=
schema
]{schema()}}
for
a
list
of
acceptable
attributes
for
a
given
trace
\
code
{
type
}
(
by
going
to
\
code
{
traces
}
-
>
\
code
{
type
}
-
>
\
code
{
attributes
})
.
Note
that
attributes
provided
at
this
level
may
override
other
arguments
(
e.g.
\
code
{plot_ly(
x
=
1
:
10
,
y
=
1
:
10
,
color
=
I(
"
red
"
),
marker
=
list
(
color
=
"
blue
"
))})
.
}
\
item
{
type
}{
A
character
string
specifying
the
trace
type (
e.g.
\
code
{
"
scatter
"
}, \
code
{
"
bar
"
}, \
code
{
"
box
"
},
etc
)
.
If
specified
,
it
\
emph
{
always
}
creates
a
trace.
Otherwise
,
a
trace
type
is
inferred
from
the
supplied
arguments
when
the
plot
is
built.
}
\
item
{
name
}{
Values
mapped
to
the
trace
'
s name attribute. Since a trace can
only have one name, this argument acts very much like
\c
ode{split} in that it
creates one trace for every unique value.}
\i
tem{color}{Values mapped to relevant
'
fill
-
color
'
attribute(s)
(e.g.
\h
ref{https://plotly.com/r/reference/#scatter-fillcolor}{fillcolor},
\h
ref{https://plotly.com/r/reference/#scatter-marker-color}{marker.color},
\h
ref{https://plotly.com/r/reference/#scatter-textfont-color}{textfont.color}, etc.).
The mapping from data values to color codes may be controlled using
\c
ode{colors} and
\c
ode{alpha}, or avoided altogether via
\c
ode{
\l
ink[=I]{I()}} (e.g.,
\c
ode{color = I("red")}).
Any color understood by
\c
ode{
\l
ink[grDevices:col2rgb]{grDevices::col2rgb()}} may be used in this way.}
\i
tem{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
\c
ode{colorRamp()}.}
\i
tem{alpha}{A number between 0 and 1 specifying the alpha channel applied to
\c
ode{color}.
Defaults to 0.5 when mapping to
\h
ref{https://plotly.com/r/reference/#scatter-fillcolor}{fillcolor} and 1 otherwise.}
\i
tem{stroke}{Similar to
\c
ode{color}, but values are mapped to relevant
'
stroke
-
color
'
attribute(s)
(e.g.,
\h
ref{https://plotly.com/r/reference/#scatter-marker-line-color}{marker.line.color}
and
\h
ref{https://plotly.com/r/reference/#scatter-line-color}{line.color}
for filled polygons). If not specified,
\c
ode{stroke} inherits from
\c
ode{color}.}
\i
tem{strokes}{Similar to
\c
ode{colors}, but controls the
\c
ode{stroke} mapping.}
\i
tem{alpha_stroke}{Similar to
\c
ode{alpha}, but applied to
\c
ode{stroke}.}
\i
tem{size}{(Numeric) values mapped to relevant
'
fill
-
size
'
attribute(s)
(e.g.,
\h
ref{https://plotly.com/r/reference/#scatter-marker-size}{marker.size},
\h
ref{https://plotly.com/r/reference/#scatter-textfont-size}{textfont.size},
and
\h
ref{https://plotly.com/r/reference/#scatter-error_x-width}{error_x.width}).
The mapping from data values to symbols may be controlled using
\c
ode{sizes}, or avoided altogether via
\c
ode{
\l
ink[=I]{I()}} (e.g.,
\c
ode{size = I(30)}).}
\i
tem{sizes}{A numeric vector of length 2 used to scale
\c
ode{size} to pixels.}
\i
tem{span}{(Numeric) values mapped to relevant
'
stroke
-
size
'
attribute(s)
(e.g.,
\h
ref{https://plotly.com/r/reference/#scatter-marker-line-width}{marker.line.width},
\h
ref{https://plotly.com/r/reference/#scatter-line-width}{line.width} for filled polygons,
and
\h
ref{https://plotly.com/r/reference/#scatter-error_x-thickness}{error_x.thickness})
The mapping from data values to symbols may be controlled using
\c
ode{spans}, or avoided altogether via
\c
ode{
\l
ink[=I]{I()}} (e.g.,
\c
ode{span = I(30)}).}
\i
tem{spans}{A numeric vector of length 2 used to scale
\c
ode{span} to pixels.}
\i
tem{symbol}{(Discrete) values mapped to
\h
ref{https://plotly.com/r/reference/#scatter-marker-symbol}{marker.symbol}.
The mapping from data values to symbols may be controlled using
\c
ode{symbols}, or avoided altogether via
\c
ode{
\l
ink[=I]{I()}} (e.g.,
\c
ode{symbol = I("pentagon")}).
Any
\l
ink{pch} value or
\h
ref{https://plotly.com/r/reference/#scatter-marker-symbol}{symbol name} may be used in this way.}
\i
tem{symbols}{A character vector of
\l
ink{pch} values or
\h
ref{https://plotly.com/r/reference/#scatter-marker-symbol}{symbol names}.}
\i
tem{linetype}{(Discrete) values mapped to
\h
ref{https://plotly.com/r/reference/#scatter-line-dash}{line.dash}.
The mapping from data values to symbols may be controlled using
\c
ode{linetypes}, or avoided altogether via
\c
ode{
\l
ink[=I]{I()}} (e.g.,
\c
ode{linetype = I("dash")}).
Any
\c
ode{lty} (see
\l
ink{par}) value or
\h
ref{https://plotly.com/r/reference/#scatter-line-dash}{dash name} may be used in this way.}
\i
tem{linetypes}{A character vector of
\c
ode{lty} values or
\h
ref{https://plotly.com/r/reference/#scatter-line-dash}{dash names}}
\i
tem{split}{(Discrete) values used to create multiple traces (one trace per value).}
\i
tem{frame}{(Discrete) values used to create animation frames.}
\i
tem{width}{Width in pixels (optional, defaults to automatic sizing).}
\i
tem{height}{Height in pixels (optional, defaults to automatic sizing).}
\i
tem{source}{a character string of length 1. Match the value of this string
with the source argument in
\c
ode{
\l
ink[=event_data]{event_data()}} to retrieve the
event data corresponding to a specific plot (shiny apps can have multiple plots).}
}
\d
escription{
This function maps R objects to
\h
ref{https://plotly.com/javascript/}{plotly.js},
an (MIT licensed) web-based interactive charting library. It provides
abstractions for doing common things (e.g. mapping data values to
fill colors (via
\c
ode{color}) or creating
\l
ink{animation}s (via
\c
ode{frame})) and sets
some different defaults to make the interface feel more
'
R
-
like
'
(i.e., closer to
\c
ode{
\l
ink[=plot]{plot()}} and
\c
ode{
\l
ink[ggplot2:qplot]{ggplot2::qplot()}}).
}
\d
etails{
Unless
\c
ode{type} is specified, this function just initiates a plotly
object with
'
global
'
attributes that are passed onto downstream uses of
\c
ode{
\l
ink[=add_trace]{add_trace()}} (or similar). A
\l
ink{formula} must always be used when
referencing column name(s) in
\c
ode{data} (e.g.
\c
ode{plot_ly(mtcars, x = ~wt)}).
Formulas are optional when supplying values directly, but they do
help inform default axis/scale titles
(e.g.,
\c
ode{plot_ly(x = mtcars$wt)} vs
\c
ode{plot_ly(x = ~mtcars$wt)})
}
\e
xamples{
\d
ontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(
\{
# examplesIf}
\d
ontrun{
# 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, but those may be over-written
plot_ly(
economics
,
x
=
~
date
,
color
=
I(
"
black
"
)) \%
>
\%
add_lines(
y
=
~
uempmed
) \%
>
\%
add_lines(
y
=
~
psavert
,
color
=
I(
"
red
"
))
#
Attributes are documented in the figure reference -> https://plotly.com/r/reference
#
You might notice plot_ly() has named arguments that aren't in this figure
#
reference. These arguments make it easier to map abstract data values to
#
visual attributes.
p
<-
plot_ly(
palmerpenguins
::
penguins
,
x
=
~
bill_length_mm
,
y
=
~
body_mass_g
)
add_markers(
p
,
color
=
~
bill_depth_mm
,
size
=
~
bill_depth_mm
)
add_markers(
p
,
color
=
~
species
)
add_markers(
p
,
color
=
~
species
,
colors
=
"
Set1
"
)
add_markers(
p
,
symbol
=
~
species
)
add_paths(
p
,
linetype
=
~
species
)
}
\
dontshow
{\})
#
examplesIf}
}
\
references
{
\
url
{
https
:
//
plotly
-
r.com
/
overview.html
}
}
\
seealso
{
\
itemize
{
\
item
For
initializing
a
plotly
-
geo
object
:
\
code
{\
link
[
=
plot_geo
]{plot_geo()}}
\
item
For
initializing
a
plotly
-
mapbox
object
:
\
code
{\
link
[
=
plot_mapbox
]{plot_mapbox()}}
\
item
For
translating
a
ggplot2
object
to
a
plotly
object
:
\
code
{\
link
[
=
ggplotly
]{ggplotly()}}
\
item
For
modifying
any
plotly
object
:
\
code
{\
link
[
=
layout
]{layout()}}, \
code
{\
link
[
=
add_trace
]{add_trace()}}, \
code
{\
link
[
=
style
]{style()}}
\
item
For
linked
brushing
:
\
code
{\
link
[
=
highlight
]{highlight()}}
\
item
For
arranging
multiple
plots
:
\
code
{\
link
[
=
subplot
]{subplot()}}, \
code
{\
link
[
crosstalk
:
bscols
]{
crosstalk
::
bscols()}}
\
item
For
inspecting
plotly
objects
:
\
code
{\
link
[
=
plotly_json
]{plotly_json()}}
\
item
For
quick
,
accurate
,
and
searchable
plotly.js
reference
:
\
code
{\
link
[
=
schema
]{schema()}}
}
}
\
author
{
Carson
Sievert
}
Back
|
FazBrowse Home
|
New Git URL