forked from plotly/plotly.R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_trace.Rd
More file actions
177 lines (137 loc) · 4.77 KB
/
add_trace.Rd
File metadata and controls
177 lines (137 loc) · 4.77 KB
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add.R
\name{add_trace}
\alias{add_area}
\alias{add_bars}
\alias{add_boxplot}
\alias{add_choropleth}
\alias{add_contour}
\alias{add_heatmap}
\alias{add_histogram}
\alias{add_histogram2d}
\alias{add_histogram2dcontour}
\alias{add_lines}
\alias{add_markers}
\alias{add_mesh}
\alias{add_paths}
\alias{add_pie}
\alias{add_polygons}
\alias{add_ribbons}
\alias{add_scattergeo}
\alias{add_segments}
\alias{add_surface}
\alias{add_text}
\alias{add_trace}
\title{Add trace(s) to a plotly visualization}
\usage{
add_trace(p, ..., data = NULL, inherit = TRUE)
add_markers(p, x = NULL, y = NULL, z = NULL, ..., data = NULL,
inherit = TRUE)
add_text(p, x = NULL, y = NULL, z = NULL, text = NULL, ...,
data = NULL, inherit = TRUE)
add_paths(p, x = NULL, y = NULL, z = NULL, ..., data = NULL,
inherit = TRUE)
add_lines(p, x = NULL, y = NULL, z = NULL, ..., data = NULL,
inherit = TRUE)
add_segments(p, x = NULL, y = NULL, xend = NULL, yend = NULL, ...,
data = NULL, inherit = TRUE)
add_polygons(p, x = NULL, y = NULL, ..., data = NULL, inherit = TRUE)
add_ribbons(p, x = NULL, ymin = NULL, ymax = NULL, ..., data = NULL,
inherit = TRUE)
add_area(p, r = NULL, t = NULL, ..., data = NULL, inherit = TRUE)
add_pie(p, values = NULL, labels = NULL, ..., data = NULL,
inherit = TRUE)
add_bars(p, x = NULL, y = NULL, ..., data = NULL, inherit = TRUE)
add_histogram(p, x = NULL, y = NULL, ..., data = NULL, inherit = TRUE)
add_histogram2d(p, x = NULL, y = NULL, z = NULL, ..., data = NULL,
inherit = TRUE)
add_histogram2dcontour(p, x = NULL, y = NULL, z = NULL, ...,
data = NULL, inherit = TRUE)
add_heatmap(p, x = NULL, y = NULL, z = NULL, ..., data = NULL,
inherit = TRUE)
add_contour(p, z = NULL, ..., data = NULL, inherit = TRUE)
add_boxplot(p, x = NULL, y = NULL, ..., data = NULL, inherit = TRUE)
add_surface(p, z = NULL, ..., data = NULL, inherit = TRUE)
add_mesh(p, x = NULL, y = NULL, z = NULL, ..., data = NULL,
inherit = TRUE)
add_scattergeo(p, ...)
add_choropleth(p, z = NULL, ..., data = NULL, inherit = TRUE)
}
\arguments{
\item{inherit}{inherit attributes from \code{\link{plot_ly}()}?}
\item{x}{the x variable.}
\item{y}{the y variable.}
\item{z}{a numeric matrix}
\item{text}{textual labels.}
\item{xend}{"final" x position (in this context, x represents "start")}
\item{yend}{"final" y position (in this context, y represents "start")}
\item{ymin}{a variable used to define the lower boundary of a polygon.}
\item{ymax}{a variable used to define the upper boundary of a polygon.}
\item{r}{For polar chart only. Sets the radial coordinates.}
\item{t}{For polar chart only. Sets the radial coordinates.}
\item{values}{the value to associated with each slice of the pie.}
\item{labels}{the labels (categories) corresponding to \code{values}.}
}
\description{
Add trace(s) to a plotly visualization
}
\examples{
p <- plot_ly(economics, x = ~date, y = ~uempmed)
p
p \%>\% add_markers()
p \%>\% add_lines()
p \%>\% add_text(text = ".")
# attributes declared in plot_ly() carry over to downstream traces,
# but can be overwritten
plot_ly(economics, x = ~date, y = ~uempmed, color = I("red")) \%>\%
add_lines() \%>\%
add_markers(color = ~pop) \%>\%
layout(showlegend = FALSE)
txhousing \%>\%
group_by(city) \%>\%
plot_ly(x = ~date, y = ~median) \%>\%
add_lines(fill = "black")
ggplot2::map_data("world", "canada") \%>\%
group_by(group) \%>\%
plot_ly(x = ~long, y = ~lat) \%>\%
add_polygons(hoverinfo = "none") \%>\%
add_markers(text = ~paste(name, "<br />", pop), hoverinfo = "text",
data = maps::canada.cities) \%>\%
layout(showlegend = FALSE)
plot_ly(economics, x = ~date) \%>\%
add_ribbons(ymin = ~pce - 1e3, ymax = ~pce + 1e3)
p <- plot_ly(plotly::wind, r = ~r, t = ~t) \%>\% add_area(color = ~nms)
layout(p, radialaxis = list(ticksuffix = "\%"), orientation = 270)
ds <- data.frame(
labels = c("A", "B", "C"),
values = c(10, 40, 60)
)
plot_ly(ds, labels = ~labels, values = ~values) \%>\%
add_pie() \%>\%
layout(title = "Basic Pie Chart using Plotly")
library(dplyr)
mtcars \%>\%
count(vs) \%>\%
plot_ly(x = ~vs, y = ~n) \%>\%
add_bars()
plot_ly(x = ~rnorm(100)) \%>\% add_histogram()
plot_ly(x = ~LETTERS, y = ~LETTERS) \%>\% add_histogram2d()
z <- as.matrix(table(LETTERS, LETTERS))
plot_ly(x = ~LETTERS, y = ~LETTERS, z = ~z) \%>\% add_histogram2d()
plot_ly(MASS::geyser, x = ~waiting, y = ~duration) \%>\%
add_histogram2dcontour()
plot_ly(z = ~volcano) \%>\% add_heatmap()
plot_ly(z = ~volcano) \%>\% add_contour()
plot_ly(mtcars, x = ~factor(vs), y = ~mpg) \%>\% add_boxplot()
plot_ly(z = ~volcano) \%>\% add_surface()
plot_ly(x = c(0, 0, 1), y = c(0, 1, 0), z = c(0, 0, 0)) \%>\% add_mesh()
}
\author{
Carson Sievert
}
\references{
\url{https://plot.ly/r/reference/}
}
\seealso{
\code{\link{plot_ly}()}
}