Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac8fc1f

Browse files
committed
update js and r docs
1 parent 6715299 commit ac8fc1f

File tree

4 files changed

+37
-40
lines changed

4 files changed

+37
-40
lines changed

_posts/plotly_js/basic/area/2015-04-09-stacked-area.html

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,9 @@
99
---
1010
var plotDiv = document.getElementById('plot');
1111
var traces = [
12-
{x: [1,2,3], y: [2,1,4], fill: 'tozeroy'},
13-
{x: [1,2,3], y: [1,1,2], fill: 'tonexty'},
14-
{x: [1,2,3], y: [3,0,2], fill: 'tonexty'}
12+
{x: [1,2,3], y: [2,1,4], stackgroup: 'one'},
13+
{x: [1,2,3], y: [1,1,2], stackgroup: 'one'},
14+
{x: [1,2,3], y: [3,0,2], stackgroup: 'one'}
1515
];
1616

17-
function stackedArea(traces) {
18-
for(var i=1; i<traces.length; i++) {
19-
for(var j=0; j<(Math.min(traces[i]['y'].length, traces[i-1]['y'].length)); j++) {
20-
traces[i]['y'][j] += traces[i-1]['y'][j];
21-
}
22-
}
23-
return traces;
24-
}
25-
26-
Plotly.newPlot(plotDiv, stackedArea(traces), {title: 'stacked and filled line chart'});
17+
Plotly.newPlot(plotDiv, traces), {title: 'stacked and filled line chart'});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: Normalized Stacked Area Chart
3+
plot_url: https://codepen.io/plotly/embed/MqzvoO/?height=463&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: area
6+
order: 2.1
7+
sitemap: false
8+
arrangement: horizontal
9+
---
10+
var plotDiv = document.getElementById('plot');
11+
var traces = [
12+
{x: [1,2,3], y: [2,1,4], stackgroup: 'one', groupnorm:'percent'},
13+
{x: [1,2,3], y: [1,1,2], stackgroup: 'one'},
14+
{x: [1,2,3], y: [3,0,2], stackgroup: 'one'}
15+
];
16+
17+
Plotly.newPlot(stacksDiv, traces, {title: 'Normalized stacked and filled line chart'});
18+

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ library(plotly)
265265
data <- t(USPersonalExpenditure)
266266
data <- data.frame("year"=rownames(data), data)
267267
268-
p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>%
268+
p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', stackgroup = 'one', fillcolor = '#F5FF8D') %>%
269269
add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>%
270270
add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>%
271271
add_trace(y = ~Personal.Care, name = 'Personal Care', fillcolor = '#700961') %>%
@@ -292,15 +292,9 @@ chart_link
292292
library(plotly)
293293
294294
data <- t(USPersonalExpenditure)
295-
data2 <- data/rowSums(data)*100
296-
data2 <- data.frame("year"=rownames(data2), data2)
297-
298-
# Transforming into a cumulative table:
299-
for (i in c(6:3)) {
300-
data2[,i-1] <- data2[,i-1] + data2[,i]
301-
}
295+
data <- data.frame("year"=rownames(data), data)
302296
303-
p <- plot_ly(data2, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>%
297+
p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', stackgroup = 'one', groupnorm = 'percent', fillcolor = '#F5FF8D') %>%
304298
add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>%
305299
add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>%
306300
add_trace(y = ~Personal.Care, name = 'Personal Care', fillcolor = '#700961') %>%

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ packageVersion('plotly')
3333
```
3434

3535
```
36-
## [1] '4.7.1.9000'
36+
## [1] '4.8.0'
3737
```
3838

3939
### Basic Filled Area Plot
@@ -57,7 +57,7 @@ chart_link = api_create(p, filename="area-basic")
5757
chart_link
5858
```
5959

60-
<iframe src="https://plot.ly/~RPlotBot/3621.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
60+
<iframe src="https://plot.ly/~RPlotBot/5322.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
6161

6262
### Filled Area Plot with Multiple Traces
6363

@@ -84,7 +84,7 @@ chart_link = api_create(p, filename="area-basic2")
8484
chart_link
8585
```
8686

87-
<iframe src="https://plot.ly/~RPlotBot/3613.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
87+
<iframe src="https://plot.ly/~RPlotBot/5324.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
8888

8989
### Selecting Hover Points
9090

@@ -141,7 +141,7 @@ chart_link = api_create(p, filename="area-hoveron")
141141
chart_link
142142
```
143143

144-
<iframe src="https://plot.ly/~RPlotBot/5224.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
144+
<iframe src="https://plot.ly/~RPlotBot/5326.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
145145

146146
### Custom Colors
147147

@@ -169,7 +169,7 @@ chart_link = api_create(p, filename="area-colors")
169169
chart_link
170170
```
171171

172-
<iframe src="https://plot.ly/~RPlotBot/3615.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
172+
<iframe src="https://plot.ly/~RPlotBot/5328.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
173173

174174
### Area Plot without Lines
175175

@@ -198,7 +198,7 @@ chart_link = api_create(p, filename="area-nolines")
198198
chart_link
199199
```
200200

201-
<iframe src="https://plot.ly/~RPlotBot/3617.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
201+
<iframe src="https://plot.ly/~RPlotBot/5330.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
202202

203203
### Interior Filling for Area Chart
204204

@@ -250,7 +250,7 @@ chart_link = api_create(p, filename="area-interior")
250250
chart_link
251251
```
252252

253-
<iframe src="https://plot.ly/~RPlotBot/3619.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
253+
<iframe src="https://plot.ly/~RPlotBot/5332.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
254254

255255
### Stacked Area Chart with Original Values
256256

@@ -261,7 +261,7 @@ library(plotly)
261261
data <- t(USPersonalExpenditure)
262262
data <- data.frame("year"=rownames(data), data)
263263

264-
p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>%
264+
p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', stackgroup = 'one', fillcolor = '#F5FF8D') %>%
265265
add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>%
266266
add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>%
267267
add_trace(y = ~Personal.Care, name = 'Personal Care', fillcolor = '#700961') %>%
@@ -278,7 +278,7 @@ chart_link = api_create(p, filename="area-stackedoriginal")
278278
chart_link
279279
```
280280

281-
<iframe src="https://plot.ly/~RPlotBot/3623.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
281+
<iframe src="https://plot.ly/~RPlotBot/5334.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
282282

283283
### Stacked Area Chart with Cumulative Values
284284

@@ -287,15 +287,9 @@ chart_link
287287
library(plotly)
288288

289289
data <- t(USPersonalExpenditure)
290-
data2 <- data/rowSums(data)*100
291-
data2 <- data.frame("year"=rownames(data2), data2)
292-
293-
# Transforming into a cumulative table:
294-
for (i in c(6:3)) {
295-
data2[,i-1] <- data2[,i-1] + data2[,i]
296-
}
290+
data <- data.frame("year"=rownames(data), data)
297291

298-
p <- plot_ly(data2, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>%
292+
p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', stackgroup = 'one', groupnorm = 'percent', fillcolor = '#F5FF8D') %>%
299293
add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>%
300294
add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>%
301295
add_trace(y = ~Personal.Care, name = 'Personal Care', fillcolor = '#700961') %>%
@@ -313,7 +307,7 @@ chart_link = api_create(p, filename="area-stackedcum")
313307
chart_link
314308
```
315309

316-
<iframe src="https://plot.ly/~RPlotBot/3625.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
310+
<iframe src="https://plot.ly/~RPlotBot/5336.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
317311

318312
#Reference
319313

0 commit comments

Comments
 (0)