Skip to content

Commit d87210b

Browse files
committed
update doc legend and minor modif
1 parent d18bbb0 commit d87210b

12 files changed

+678
-351
lines changed

_posts/r/2015-07-30-filled-area-plots.Rmd

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ library(plotly)
4646
4747
density <- density(diamonds$carat)
4848
49-
plot_ly(x = ~density$x, y = ~density$y, type = 'scatter', mode = 'lines', fill = 'tozeroy') %>%
49+
p <- plot_ly(x = ~density$x, y = ~density$y, type = 'scatter', mode = 'lines', fill = 'tozeroy') %>%
5050
layout(xaxis = list(title = 'Carat'),
5151
yaxis = list(title = 'Density'))
52+
53+
# Create a shareable link to your chart
54+
# Set up API credentials: https://plot.ly/r/getting-started
55+
chart_link = plotly_POST(p, filename="area/basic")
56+
chart_link
5257
```
5358

5459
```{r, echo=FALSE}
55-
plotly_POST(filename="area/basic")
60+
chart_link
5661
```
5762

5863
### Filled Area Plot with Multiple Traces
@@ -68,14 +73,19 @@ density1 <- density(diamonds1$carat)
6873
diamonds2 <- diamonds[which(diamonds$cut == "Ideal"),]
6974
density2 <- density(diamonds2$carat)
7075
71-
plot_ly(x = ~density1$x, y = ~density1$y, type = 'scatter', mode = 'lines', name = 'Fair cut', fill = 'tozeroy') %>%
76+
p <- plot_ly(x = ~density1$x, y = ~density1$y, type = 'scatter', mode = 'lines', name = 'Fair cut', fill = 'tozeroy') %>%
7277
add_trace(x = ~density2$x, y = ~density2$y, name = 'Ideal cut', fill = 'tozeroy') %>%
7378
layout(xaxis = list(title = 'Carat'),
7479
yaxis = list(title = 'Density'))
80+
81+
# Create a shareable link to your chart
82+
# Set up API credentials: https://plot.ly/r/getting-started
83+
chart_link = plotly_POST(p, filename="area/basic2")
84+
chart_link
7585
```
7686

7787
```{r, echo=FALSE}
78-
plotly_POST(filename="area/basic2")
88+
chart_link
7989
```
8090

8191
### Custom Colors
@@ -89,17 +99,22 @@ density1 <- density(diamonds1$carat)
8999
diamonds2 <- diamonds[which(diamonds$cut == "Ideal"),]
90100
density2 <- density(diamonds2$carat)
91101
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',
93103
fillcolor = 'rgba(168, 216, 234, 0.5)',
94104
line = list(width = 0.5)) %>%
95105
add_trace(x = ~density2$x, y = ~density2$y, name = 'Ideal cut', fill = 'tozeroy',
96106
fillcolor = 'rgba(255, 212, 96, 0.5)') %>%
97107
layout(xaxis = list(title = 'Carat'),
98108
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
99114
```
100115

101116
```{r, echo=FALSE}
102-
plotly_POST(filename="area/colors")
117+
chart_link
103118
```
104119

105120
### Area Plot without Lines
@@ -115,16 +130,21 @@ density1 <- density(diamonds1$carat)
115130
diamonds2 <- diamonds[which(diamonds$cut == "Ideal"),]
116131
density2 <- density(diamonds2$carat)
117132
118-
plot_ly(x = ~density1$x, y = ~density1$y, type = 'scatter', mode = 'none', name = 'Fair cut', fill = 'tozeroy',
133+
p <- plot_ly(x = ~density1$x, y = ~density1$y, type = 'scatter', mode = 'none', name = 'Fair cut', fill = 'tozeroy',
119134
fillcolor = 'rgba(168, 216, 234, 0.5)') %>%
120135
add_trace(x = ~density2$x, y = ~density2$y, name = 'Ideal cut', fill = 'tozeroy',
121136
fillcolor = 'rgba(255, 212, 96, 0.5)') %>%
122137
layout(xaxis = list(title = 'Carat'),
123138
yaxis = list(title = 'Density'))
139+
140+
# Create a shareable link to your chart
141+
# Set up API credentials: https://plot.ly/r/getting-started
142+
chart_link = plotly_POST(p, filename="area/nolines")
143+
chart_link
124144
```
125145

126146
```{r, echo=FALSE}
127-
plotly_POST(filename="area/nolines")
147+
chart_link
128148
```
129149

130150
### Interior Filling for Area Chart
@@ -145,7 +165,7 @@ data$average_2014 <- rowMeans(data[,c("high_2014", "low_2014")])
145165
#The default order will be alphabetized unless specified as below:
146166
data$month <- factor(data$month, levels = data[["month"]])
147167
148-
plot_ly(data, x = ~month, y = ~high_2014, type = 'scatter', mode = 'lines',
168+
p <- plot_ly(data, x = ~month, y = ~high_2014, type = 'scatter', mode = 'lines',
149169
line = list(color = 'rgba(0,100,80,1)'),
150170
showlegend = FALSE, name = 'High 2014') %>%
151171
add_trace(y = ~low_2014, type = 'scatter', mode = 'lines',
@@ -169,10 +189,15 @@ plot_ly(data, x = ~month, y = ~high_2014, type = 'scatter', mode = 'lines',
169189
tickcolor = 'rgb(127,127,127)',
170190
ticks = 'outside',
171191
zeroline = FALSE))
192+
193+
# Create a shareable link to your chart
194+
# Set up API credentials: https://plot.ly/r/getting-started
195+
chart_link = plotly_POST(p, filename="area/interior")
196+
chart_link
172197
```
173198

174199
```{r, echo=FALSE}
175-
plotly_POST(filename="area/interior")
200+
chart_link
176201
```
177202

178203
### Stacked Area Chart with Original Values
@@ -183,7 +208,7 @@ library(plotly)
183208
data <- t(USPersonalExpenditure)
184209
data <- data.frame("year"=rownames(data), data)
185210
186-
plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>%
211+
p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>%
187212
add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>%
188213
add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>%
189214
add_trace(y = ~Personal.Care, name = 'Personal Care', fillcolor = '#700961') %>%
@@ -193,10 +218,15 @@ plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type
193218
showgrid = FALSE),
194219
yaxis = list(title = "Expenditures (in billions of dollars)",
195220
showgrid = FALSE))
221+
222+
# Create a shareable link to your chart
223+
# Set up API credentials: https://plot.ly/r/getting-started
224+
chart_link = plotly_POST(p, filename="area/stackedoriginal")
225+
chart_link
196226
```
197227

198228
```{r, echo=FALSE}
199-
plotly_POST(filename="area/stackedoriginal")
229+
chart_link
200230
```
201231

202232
### Stacked Area Chart with Cumulative Values
@@ -213,7 +243,7 @@ for (i in c(6:3)) {
213243
data2[,i-1] <- data2[,i-1] + data2[,i]
214244
}
215245
216-
plot_ly(data2, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>%
246+
p <- plot_ly(data2, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>%
217247
add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>%
218248
add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>%
219249
add_trace(y = ~Personal.Care, name = 'Personal Care', fillcolor = '#700961') %>%
@@ -224,10 +254,15 @@ plot_ly(data2, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type
224254
yaxis = list(title = "Proportion from the Total Expenditures",
225255
showgrid = FALSE,
226256
ticksuffix = '%'))
257+
258+
# Create a shareable link to your chart
259+
# Set up API credentials: https://plot.ly/r/getting-started
260+
chart_link = plotly_POST(p, filename="area/stackedcum")
261+
chart_link
227262
```
228263

229264
```{r, echo=FALSE}
230-
plotly_POST(filename="area/stackedcum")
265+
chart_link
231266
```
232267

233268
#Reference

_posts/r/2015-07-30-filled-area-plots.md

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ packageVersion('plotly')
3434
```
3535

3636
```
37-
## [1] '4.5.2'
37+
## [1] '4.5.5.9000'
3838
```
3939

4040
### Basic Filled Area Plot
@@ -48,9 +48,14 @@ library(plotly)
4848

4949
density <- density(diamonds$carat)
5050

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') %>%
5252
layout(xaxis = list(title = 'Carat'),
5353
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
5459
```
5560

5661
<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)
6974
diamonds2 <- diamonds[which(diamonds$cut == "Ideal"),]
7075
density2 <- density(diamonds2$carat)
7176

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') %>%
7378
add_trace(x = ~density2$x, y = ~density2$y, name = 'Ideal cut', fill = 'tozeroy') %>%
7479
layout(xaxis = list(title = 'Carat'),
7580
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
7686
```
7787

7888
<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)
8999
diamonds2 <- diamonds[which(diamonds$cut == "Ideal"),]
90100
density2 <- density(diamonds2$carat)
91101

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',
93103
fillcolor = 'rgba(168, 216, 234, 0.5)',
94104
line = list(width = 0.5)) %>%
95105
add_trace(x = ~density2$x, y = ~density2$y, name = 'Ideal cut', fill = 'tozeroy',
96106
fillcolor = 'rgba(255, 212, 96, 0.5)') %>%
97107
layout(xaxis = list(title = 'Carat'),
98108
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
99114
```
100115

101116
<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)
114129
diamonds2 <- diamonds[which(diamonds$cut == "Ideal"),]
115130
density2 <- density(diamonds2$carat)
116131

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',
118133
fillcolor = 'rgba(168, 216, 234, 0.5)') %>%
119134
add_trace(x = ~density2$x, y = ~density2$y, name = 'Ideal cut', fill = 'tozeroy',
120135
fillcolor = 'rgba(255, 212, 96, 0.5)') %>%
121136
layout(xaxis = list(title = 'Carat'),
122137
yaxis = list(title = 'Density'))
123-
```
124138

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
127143
```
128144

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>
133146

134147
### Interior Filling for Area Chart
135148

@@ -150,7 +163,7 @@ data$average_2014 <- rowMeans(data[,c("high_2014", "low_2014")])
150163
#The default order will be alphabetized unless specified as below:
151164
data$month <- factor(data$month, levels = data[["month"]])
152165

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',
154167
line = list(color = 'rgba(0,100,80,1)'),
155168
showlegend = FALSE, name = 'High 2014') %>%
156169
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',
174187
tickcolor = 'rgb(127,127,127)',
175188
ticks = 'outside',
176189
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
177195
```
178196

179197
<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)
187205
data <- t(USPersonalExpenditure)
188206
data <- data.frame("year"=rownames(data), data)
189207

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') %>%
191209
add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>%
192210
add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>%
193211
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
197215
showgrid = FALSE),
198216
yaxis = list(title = "Expenditures (in billions of dollars)",
199217
showgrid = FALSE))
200-
```
201218

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
204223
```
205224

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>
210226

211227
### Stacked Area Chart with Cumulative Values
212228

@@ -223,7 +239,7 @@ for (i in c(6:3)) {
223239
data2[,i-1] <- data2[,i-1] + data2[,i]
224240
}
225241

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') %>%
227243
add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>%
228244
add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>%
229245
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
234250
yaxis = list(title = "Proportion from the Total Expenditures",
235251
showgrid = FALSE,
236252
ticksuffix = '%'))
237-
```
238253

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
239258
```
240-
## Error in traces[[i]][[obj]]: attempt to select less than one element
241-
```
242-
243259

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>
247261

248262
#Reference
249263

0 commit comments

Comments
 (0)