@@ -34,7 +34,7 @@ packageVersion('plotly')
34
34
```
35
35
36
36
```
37
- ## [1] '4.5.2 '
37
+ ## [1] '4.5.5.9000 '
38
38
```
39
39
40
40
### Basic Filled Area Plot
@@ -48,9 +48,14 @@ library(plotly)
48
48
49
49
density <- density(diamonds $ carat )
50
50
51
- plot_ly(x = ~ density $ x , y = ~ density $ y , type = ' scatter' , mode = ' lines' , fill = ' tozeroy' ) %> %
51
+ p <- plot_ly(x = ~ density $ x , y = ~ density $ y , type = ' scatter' , mode = ' lines' , fill = ' tozeroy' ) %> %
52
52
layout(xaxis = list (title = ' Carat' ),
53
53
yaxis = list (title = ' Density' ))
54
+
55
+ # Create a shareable link to your chart
56
+ # Set up API credentials: https://plot.ly/r/getting-started
57
+ chart_link = plotly_POST(p , filename = " area/basic" )
58
+ chart_link
54
59
```
55
60
56
61
<iframe src =" https://plot.ly/~RPlotBot/3621.embed " width =" 800 " height =" 600 " id =" igraph " scrolling =" no " seamless =" seamless " frameBorder =" 0 " > </iframe >
@@ -69,10 +74,15 @@ density1 <- density(diamonds1$carat)
69
74
diamonds2 <- diamonds [which(diamonds $ cut == " Ideal" ),]
70
75
density2 <- density(diamonds2 $ carat )
71
76
72
- plot_ly(x = ~ density1 $ x , y = ~ density1 $ y , type = ' scatter' , mode = ' lines' , name = ' Fair cut' , fill = ' tozeroy' ) %> %
77
+ p <- plot_ly(x = ~ density1 $ x , y = ~ density1 $ y , type = ' scatter' , mode = ' lines' , name = ' Fair cut' , fill = ' tozeroy' ) %> %
73
78
add_trace(x = ~ density2 $ x , y = ~ density2 $ y , name = ' Ideal cut' , fill = ' tozeroy' ) %> %
74
79
layout(xaxis = list (title = ' Carat' ),
75
80
yaxis = list (title = ' Density' ))
81
+
82
+ # Create a shareable link to your chart
83
+ # Set up API credentials: https://plot.ly/r/getting-started
84
+ chart_link = plotly_POST(p , filename = " area/basic2" )
85
+ chart_link
76
86
```
77
87
78
88
<iframe src =" https://plot.ly/~RPlotBot/3613.embed " width =" 800 " height =" 600 " id =" igraph " scrolling =" no " seamless =" seamless " frameBorder =" 0 " > </iframe >
@@ -89,13 +99,18 @@ density1 <- density(diamonds1$carat)
89
99
diamonds2 <- diamonds [which(diamonds $ cut == " Ideal" ),]
90
100
density2 <- density(diamonds2 $ carat )
91
101
92
- plot_ly(x = ~ density1 $ x , y = ~ density1 $ y , type = ' scatter' , mode = ' lines' , name = ' Fair cut' , fill = ' tozeroy' ,
102
+ p <- plot_ly(x = ~ density1 $ x , y = ~ density1 $ y , type = ' scatter' , mode = ' lines' , name = ' Fair cut' , fill = ' tozeroy' ,
93
103
fillcolor = ' rgba(168, 216, 234, 0.5)' ,
94
104
line = list (width = 0.5 )) %> %
95
105
add_trace(x = ~ density2 $ x , y = ~ density2 $ y , name = ' Ideal cut' , fill = ' tozeroy' ,
96
106
fillcolor = ' rgba(255, 212, 96, 0.5)' ) %> %
97
107
layout(xaxis = list (title = ' Carat' ),
98
108
yaxis = list (title = ' Density' ))
109
+
110
+ # Create a shareable link to your chart
111
+ # Set up API credentials: https://plot.ly/r/getting-started
112
+ chart_link = plotly_POST(p , filename = " area/colors" )
113
+ chart_link
99
114
```
100
115
101
116
<iframe src =" https://plot.ly/~RPlotBot/3615.embed " width =" 800 " height =" 600 " id =" igraph " scrolling =" no " seamless =" seamless " frameBorder =" 0 " > </iframe >
@@ -114,22 +129,20 @@ density1 <- density(diamonds1$carat)
114
129
diamonds2 <- diamonds [which(diamonds $ cut == " Ideal" ),]
115
130
density2 <- density(diamonds2 $ carat )
116
131
117
- plot_ly(x = ~ density1 $ x , y = ~ density1 $ y , type = ' scatter' , mode = ' none' , name = ' Fair cut' , fill = ' tozeroy' ,
132
+ p <- plot_ly(x = ~ density1 $ x , y = ~ density1 $ y , type = ' scatter' , mode = ' none' , name = ' Fair cut' , fill = ' tozeroy' ,
118
133
fillcolor = ' rgba(168, 216, 234, 0.5)' ) %> %
119
134
add_trace(x = ~ density2 $ x , y = ~ density2 $ y , name = ' Ideal cut' , fill = ' tozeroy' ,
120
135
fillcolor = ' rgba(255, 212, 96, 0.5)' ) %> %
121
136
layout(xaxis = list (title = ' Carat' ),
122
137
yaxis = list (title = ' Density' ))
123
- ```
124
138
125
- ```
126
- ## Error in traces[[i]][[obj]]: attempt to select less than one element
139
+ # Create a shareable link to your chart
140
+ # Set up API credentials: https://plot.ly/r/getting-started
141
+ chart_link = plotly_POST(p , filename = " area/nolines" )
142
+ chart_link
127
143
```
128
144
129
-
130
- ```
131
- ## Error in traces[[i]][[obj]]: attempt to select less than one element
132
- ```
145
+ <iframe src =" https://plot.ly/~RPlotBot/3617.embed " width =" 800 " height =" 600 " id =" igraph " scrolling =" no " seamless =" seamless " frameBorder =" 0 " > </iframe >
133
146
134
147
### Interior Filling for Area Chart
135
148
@@ -150,7 +163,7 @@ data$average_2014 <- rowMeans(data[,c("high_2014", "low_2014")])
150
163
# The default order will be alphabetized unless specified as below:
151
164
data $ month <- factor (data $ month , levels = data [[" month" ]])
152
165
153
- plot_ly(data , x = ~ month , y = ~ high_2014 , type = ' scatter' , mode = ' lines' ,
166
+ p <- plot_ly(data , x = ~ month , y = ~ high_2014 , type = ' scatter' , mode = ' lines' ,
154
167
line = list (color = ' rgba(0,100,80,1)' ),
155
168
showlegend = FALSE , name = ' High 2014' ) %> %
156
169
add_trace(y = ~ low_2014 , type = ' scatter' , mode = ' lines' ,
@@ -174,6 +187,11 @@ plot_ly(data, x = ~month, y = ~high_2014, type = 'scatter', mode = 'lines',
174
187
tickcolor = ' rgb(127,127,127)' ,
175
188
ticks = ' outside' ,
176
189
zeroline = FALSE ))
190
+
191
+ # Create a shareable link to your chart
192
+ # Set up API credentials: https://plot.ly/r/getting-started
193
+ chart_link = plotly_POST(p , filename = " area/interior" )
194
+ chart_link
177
195
```
178
196
179
197
<iframe src =" https://plot.ly/~RPlotBot/3619.embed " width =" 800 " height =" 600 " id =" igraph " scrolling =" no " seamless =" seamless " frameBorder =" 0 " > </iframe >
@@ -187,7 +205,7 @@ library(plotly)
187
205
data <- t(USPersonalExpenditure )
188
206
data <- data.frame (" year" = rownames(data ), data )
189
207
190
- plot_ly(data , x = ~ year , y = ~ Food.and.Tobacco , name = ' Food and Tobacco' , type = ' scatter' , mode = ' none' , fill = ' tozeroy' , fillcolor = ' #F5FF8D' ) %> %
208
+ p <- plot_ly(data , x = ~ year , y = ~ Food.and.Tobacco , name = ' Food and Tobacco' , type = ' scatter' , mode = ' none' , fill = ' tozeroy' , fillcolor = ' #F5FF8D' ) %> %
191
209
add_trace(y = ~ Household.Operation , name = ' Household Operation' , fillcolor = ' #50CB86' ) %> %
192
210
add_trace(y = ~ Medical.and.Health , name = ' Medical and Health' , fillcolor = ' #4C74C9' ) %> %
193
211
add_trace(y = ~ Personal.Care , name = ' Personal Care' , fillcolor = ' #700961' ) %> %
@@ -197,16 +215,14 @@ plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type
197
215
showgrid = FALSE ),
198
216
yaxis = list (title = " Expenditures (in billions of dollars)" ,
199
217
showgrid = FALSE ))
200
- ```
201
218
202
- ```
203
- ## Error in traces[[i]][[obj]]: attempt to select less than one element
219
+ # Create a shareable link to your chart
220
+ # Set up API credentials: https://plot.ly/r/getting-started
221
+ chart_link = plotly_POST(p , filename = " area/stackedoriginal" )
222
+ chart_link
204
223
```
205
224
206
-
207
- ```
208
- ## Error in traces[[i]][[obj]]: attempt to select less than one element
209
- ```
225
+ <iframe src =" https://plot.ly/~RPlotBot/3623.embed " width =" 800 " height =" 600 " id =" igraph " scrolling =" no " seamless =" seamless " frameBorder =" 0 " > </iframe >
210
226
211
227
### Stacked Area Chart with Cumulative Values
212
228
@@ -223,7 +239,7 @@ for (i in c(6:3)) {
223
239
data2 [,i - 1 ] <- data2 [,i - 1 ] + data2 [,i ]
224
240
}
225
241
226
- plot_ly(data2 , x = ~ year , y = ~ Food.and.Tobacco , name = ' Food and Tobacco' , type = ' scatter' , mode = ' none' , fill = ' tozeroy' , fillcolor = ' #F5FF8D' ) %> %
242
+ p <- plot_ly(data2 , x = ~ year , y = ~ Food.and.Tobacco , name = ' Food and Tobacco' , type = ' scatter' , mode = ' none' , fill = ' tozeroy' , fillcolor = ' #F5FF8D' ) %> %
227
243
add_trace(y = ~ Household.Operation , name = ' Household Operation' , fillcolor = ' #50CB86' ) %> %
228
244
add_trace(y = ~ Medical.and.Health , name = ' Medical and Health' , fillcolor = ' #4C74C9' ) %> %
229
245
add_trace(y = ~ Personal.Care , name = ' Personal Care' , fillcolor = ' #700961' ) %> %
@@ -234,16 +250,14 @@ plot_ly(data2, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type
234
250
yaxis = list (title = " Proportion from the Total Expenditures" ,
235
251
showgrid = FALSE ,
236
252
ticksuffix = ' %' ))
237
- ```
238
253
254
+ # Create a shareable link to your chart
255
+ # Set up API credentials: https://plot.ly/r/getting-started
256
+ chart_link = plotly_POST(p , filename = " area/stackedcum" )
257
+ chart_link
239
258
```
240
- ## Error in traces[[i]][[obj]]: attempt to select less than one element
241
- ```
242
-
243
259
244
- ```
245
- ## Error in traces[[i]][[obj]]: attempt to select less than one element
246
- ```
260
+ <iframe src =" https://plot.ly/~RPlotBot/3625.embed " width =" 800 " height =" 600 " id =" igraph " scrolling =" no " seamless =" seamless " frameBorder =" 0 " > </iframe >
247
261
248
262
#Reference
249
263
0 commit comments