diff --git a/_posts/plotly_js/basic/area/2015-04-09-stacked-area.html b/_posts/plotly_js/basic/area/2015-04-09-stacked-area.html index 828c77a438d1..e270557e1418 100644 --- a/_posts/plotly_js/basic/area/2015-04-09-stacked-area.html +++ b/_posts/plotly_js/basic/area/2015-04-09-stacked-area.html @@ -9,18 +9,9 @@ --- var plotDiv = document.getElementById('plot'); var traces = [ - {x: [1,2,3], y: [2,1,4], fill: 'tozeroy'}, - {x: [1,2,3], y: [1,1,2], fill: 'tonexty'}, - {x: [1,2,3], y: [3,0,2], fill: 'tonexty'} + {x: [1,2,3], y: [2,1,4], stackgroup: 'one'}, + {x: [1,2,3], y: [1,1,2], stackgroup: 'one'}, + {x: [1,2,3], y: [3,0,2], stackgroup: 'one'} ]; -function stackedArea(traces) { - for(var i=1; i<traces.length; i++) { - for(var j=0; j<(Math.min(traces[i]['y'].length, traces[i-1]['y'].length)); j++) { - traces[i]['y'][j] += traces[i-1]['y'][j]; - } - } - return traces; -} - -Plotly.newPlot(plotDiv, stackedArea(traces), {title: 'stacked and filled line chart'}); +Plotly.newPlot(plotDiv, traces), {title: 'stacked and filled line chart'}); diff --git a/_posts/plotly_js/basic/area/2018-09-18-normalized-stacked-area.html b/_posts/plotly_js/basic/area/2018-09-18-normalized-stacked-area.html new file mode 100644 index 000000000000..98c546c7c593 --- /dev/null +++ b/_posts/plotly_js/basic/area/2018-09-18-normalized-stacked-area.html @@ -0,0 +1,18 @@ +--- +name: Normalized Stacked Area Chart +plot_url: https://codepen.io/plotly/embed/MqzvoO/?height=463&theme-id=15263&default-tab=result +language: plotly_js +suite: area +order: 2.1 +sitemap: false +arrangement: horizontal +--- +var plotDiv = document.getElementById('plot'); +var traces = [ + {x: [1,2,3], y: [2,1,4], stackgroup: 'one', groupnorm:'percent'}, + {x: [1,2,3], y: [1,1,2], stackgroup: 'one'}, + {x: [1,2,3], y: [3,0,2], stackgroup: 'one'} +]; + +Plotly.newPlot(stacksDiv, traces, {title: 'Normalized stacked and filled line chart'}); + diff --git a/_posts/python/basic/area/2015-06-30-area.html b/_posts/python/basic/area/2015-06-30-area.html index c4e5d150655b..137c38298932 100644 --- a/_posts/python/basic/area/2015-06-30-area.html +++ b/_posts/python/basic/area/2015-06-30-area.html @@ -15,8 +15,7 @@ page_type: u-guide --- {% raw %} -
-
+
@@ -30,10 +29,10 @@

Version Check
-
In [4]:
+
In [1]:
-
-
+
@@ -71,11 +71,11 @@

Basic Overlaid Area Chart
-
In [5]:
+
In [2]:
-
import plotly.plotly as py
-import plotly.graph_objs as go
+
@@ -114,8 +116,7 @@ 

Basic Overlaid Area Chart -
+
@@ -125,11 +126,11 @@

Overlaid Area Chart Without

-
In [6]:
+
In [3]:
-
import plotly.plotly as py
-import plotly.graph_objs as go
+
import plotly.plotly as py
+import plotly.graph_objs as go
 
 trace1 = go.Scatter(
     x=[1, 2, 3, 4],
@@ -157,11 +158,13 @@ 

Overlaid Area Chart Without
-
Out[6]:
+ +
Out[3]:
+
- +
@@ -170,8 +173,7 @@

Overlaid Area Chart Without

-
-
+
@@ -181,16 +183,16 @@

Interior Filling for Area Chart
-
In [7]:
+
In [4]:
- -
-
+
-
In [8]:
+
In [5]:
-
import plotly.plotly as py
-import plotly.graph_objs as go
+
import plotly.plotly as py
+import plotly.graph_objs as go
 
-trace0 = go.Scatter(
-    x=['Winter', 'Spring', 'Summer', 'Fall'],
-    y=['40', '20', '30', '40'],
+# Add original data
+x=['Winter', 'Spring', 'Summer', 'Fall']
+
+trace0 = dict(
+    x=x,
+    y=[40, 60, 40, 10],
+    hoverinfo='x+y',
     mode='lines',
     line=dict(width=0.5,
-              color='rgb(184, 247, 212)'),
-    fill='tonexty'
+              color='rgb(131, 90, 241)'),
+    stackgroup='one'
 )
-trace1 = go.Scatter(
-    x=['Winter', 'Spring', 'Summer', 'Fall'],
-    y=['50', '70', '40', '60'],
+trace1 = dict(
+    x=x,
+    y=[20, 10, 10, 60],
+    hoverinfo='x+y',
     mode='lines',
     line=dict(width=0.5,
               color='rgb(111, 231, 219)'),
-    fill='tonexty'
+    stackgroup='one'
 )
-trace2 = go.Scatter(
-    x=['Winter', 'Spring', 'Summer', 'Fall'],
-    y=['70', '80', '60', '70'],
-    mode='lines',
-    line=dict(width=0.5,
-              color='rgb(127, 166, 238)'),
-    fill='tonexty'
-)
-trace3 = go.Scatter(
-    x=['Winter', 'Spring', 'Summer', 'Fall'],
-    y=['100', '100', '100', '100'],
+trace2 = dict(
+    x=x,
+    y=[40, 30, 50, 30],
+    hoverinfo='x+y',
     mode='lines',
     line=dict(width=0.5,
-              color='rgb(131, 90, 241)'),
-    fill='tonexty'
-)
-data = [trace0, trace1, trace2, trace3]
-layout = go.Layout(
-    showlegend=True,
-    xaxis=dict(
-        type='category',
-    ),
-    yaxis=dict(
-        type='linear',
-        range=[1, 100],
-        dtick=20,
-        ticksuffix='%'
-    )
+              color='rgb(184, 247, 212)'),
+    stackgroup='one'
 )
-fig = go.Figure(data=data, layout=layout)
-py.iplot(fig, filename='stacked-area-plot')
+data = [trace0, trace1, trace2]
+
+fig = dict(data=data)
+py.iplot(fig, filename='stacked-area-plot-hover', validate=False)
 
@@ -307,11 +297,13 @@

Stacked Area Chart with Cumul
-
Out[8]:
+ +
Out[5]:
+
- +
@@ -320,74 +312,70 @@

Stacked Area Chart with Cumul

-
-
+
-
In [9]:
+
In [6]:
-
import plotly.plotly as py
-import plotly.graph_objs as go
+
import plotly.plotly as py
+import plotly.graph_objs as go
 
-# Add original data
-x=['Winter', 'Spring', 'Summer', 'Fall']
-
-y0_org=[40, 60, 40, 10]
-y1_org=[20, 10, 10, 60]
-y2_org=[40, 30, 50, 30]
-
-# Add data to create cumulative stacked values
-y0_stck=y0_org
-y1_stck=[y0+y1 for y0, y1 in zip(y0_org, y1_org)]
-y2_stck=[y0+y1+y2 for y0, y1, y2 in zip(y0_org, y1_org, y2_org)]
-
-# Make original values strings and add % for hover text
-y0_txt=[str(y0)+'%' for y0 in y0_org]
-y1_txt=[str(y1)+'%' for y1 in y1_org]
-y2_txt=[str(y2)+'%' for y2 in y2_org]
-
-trace0 = go.Scatter(
-    x=x,
-    y=y0_stck,
-    text=y0_txt,
-    hoverinfo='x+text',
+trace0 = dict(
+    x=['Winter', 'Spring', 'Summer', 'Fall'],
+    y=['40', '20', '30', '40'],
     mode='lines',
     line=dict(width=0.5,
-              color='rgb(131, 90, 241)'),
-    fill='tonexty'
+              color='rgb(184, 247, 212)'),
+    stackgroup='one',
+    groupnorm='percent'
 )
-trace1 = go.Scatter(
-    x=x,
-    y=y1_stck,
-    text=y1_txt,
-    hoverinfo='x+text',
+trace1 = dict(
+    x=['Winter', 'Spring', 'Summer', 'Fall'],
+    y=['50', '70', '40', '60'],
     mode='lines',
     line=dict(width=0.5,
               color='rgb(111, 231, 219)'),
-    fill='tonexty'
+    stackgroup='one'
 )
-trace2 = go.Scatter(
-    x=x,
-    y=y2_stck,
-    text=y2_txt,
-    hoverinfo='x+text',
+trace2 = dict(
+    x=['Winter', 'Spring', 'Summer', 'Fall'],
+    y=['70', '80', '60', '70'],
     mode='lines',
     line=dict(width=0.5,
-              color='rgb(184, 247, 212)'),
-    fill='tonexty'
+              color='rgb(127, 166, 238)'),
+    stackgroup='one'
 )
-data = [trace0, trace1, trace2]
-
-fig = go.Figure(data=data)
-py.iplot(fig, filename='stacked-area-plot-hover')
+trace3 = dict(
+    x=['Winter', 'Spring', 'Summer', 'Fall'],
+    y=['100', '100', '100', '100'],
+    mode='lines',
+    line=dict(width=0.5,
+              color='rgb(131, 90, 241)'),
+    stackgroup='one'
+)
+data = [trace0, trace1, trace2, trace3]
+layout = go.Layout(
+    showlegend=True,
+    xaxis=dict(
+        type='category',
+    ),
+    yaxis=dict(
+        type='linear',
+        range=[1, 100],
+        dtick=20,
+        ticksuffix='%'
+    )
+)
+fig = dict(data=data, layout=layout)
+py.iplot(fig, filename='stacked-area-plot-norm', validate=False)
 
@@ -399,11 +387,13 @@

Stacked Area Chart with Origina
-
Out[9]:
+ +
Out[6]:
+
- +
@@ -412,8 +402,7 @@

Stacked Area Chart with Origina

-
-
+
@@ -423,11 +412,11 @@

Select Hover Points
-
In [10]:
+
In [7]:
-
import plotly.plotly as py
-import plotly.graph_objs as go
+
@@ -493,8 +484,7 @@ 

Select Hover Points -
+
diff --git a/_posts/python/basic/area/area.ipynb b/_posts/python/basic/area/area.ipynb index ea2ea838171f..c64f5ecb218f 100644 --- a/_posts/python/basic/area/area.ipynb +++ b/_posts/python/basic/area/area.ipynb @@ -14,16 +14,16 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'2.2.3'" + "'3.1.1'" ] }, - "execution_count": 4, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -35,16 +35,14 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ "#### Basic Overlaid Area Chart" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -56,7 +54,7 @@ "" ] }, - "execution_count": 5, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -82,16 +80,14 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ "#### Overlaid Area Chart Without Boundary Lines" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -103,7 +99,7 @@ "" ] }, - "execution_count": 6, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -131,16 +127,14 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ "#### Interior Filling for Area Chart" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -152,7 +146,7 @@ "" ] }, - "execution_count": 7, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -186,28 +180,26 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ - "### Stacked Area Chart with Cumulative Values" + "#### Stacked Area Chart" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 8, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -216,77 +208,64 @@ "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "\n", - "trace0 = go.Scatter(\n", - " x=['Winter', 'Spring', 'Summer', 'Fall'],\n", - " y=['40', '20', '30', '40'],\n", + "# Add original data\n", + "x=['Winter', 'Spring', 'Summer', 'Fall']\n", + "\n", + "trace0 = dict(\n", + " x=x,\n", + " y=[40, 60, 40, 10],\n", + " hoverinfo='x+y',\n", " mode='lines',\n", " line=dict(width=0.5,\n", - " color='rgb(184, 247, 212)'),\n", - " fill='tonexty'\n", + " color='rgb(131, 90, 241)'),\n", + " stackgroup='one'\n", ")\n", - "trace1 = go.Scatter(\n", - " x=['Winter', 'Spring', 'Summer', 'Fall'],\n", - " y=['50', '70', '40', '60'],\n", + "trace1 = dict(\n", + " x=x,\n", + " y=[20, 10, 10, 60],\n", + " hoverinfo='x+y',\n", " mode='lines',\n", " line=dict(width=0.5,\n", " color='rgb(111, 231, 219)'),\n", - " fill='tonexty'\n", + " stackgroup='one'\n", ")\n", - "trace2 = go.Scatter(\n", - " x=['Winter', 'Spring', 'Summer', 'Fall'],\n", - " y=['70', '80', '60', '70'],\n", - " mode='lines',\n", - " line=dict(width=0.5,\n", - " color='rgb(127, 166, 238)'),\n", - " fill='tonexty'\n", - ")\n", - "trace3 = go.Scatter(\n", - " x=['Winter', 'Spring', 'Summer', 'Fall'],\n", - " y=['100', '100', '100', '100'],\n", + "trace2 = dict(\n", + " x=x,\n", + " y=[40, 30, 50, 30],\n", + " hoverinfo='x+y',\n", " mode='lines',\n", " line=dict(width=0.5,\n", - " color='rgb(131, 90, 241)'),\n", - " fill='tonexty'\n", - ")\n", - "data = [trace0, trace1, trace2, trace3]\n", - "layout = go.Layout(\n", - " showlegend=True,\n", - " xaxis=dict(\n", - " type='category',\n", - " ),\n", - " yaxis=dict(\n", - " type='linear',\n", - " range=[1, 100],\n", - " dtick=20,\n", - " ticksuffix='%'\n", - " )\n", + " color='rgb(184, 247, 212)'),\n", + " stackgroup='one'\n", ")\n", - "fig = go.Figure(data=data, layout=layout)\n", - "py.iplot(fig, filename='stacked-area-plot')" + "data = [trace0, trace1, trace2]\n", + "\n", + "fig = dict(data=data)\n", + "py.iplot(fig, filename='stacked-area-plot-hover', validate=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "#### Stacked Area Chart with Original Values" + "### Stacked Area Chart with Normalized Values" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 9, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -295,57 +274,54 @@ "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "\n", - "# Add original data\n", - "x=['Winter', 'Spring', 'Summer', 'Fall']\n", - "\n", - "y0_org=[40, 60, 40, 10]\n", - "y1_org=[20, 10, 10, 60]\n", - "y2_org=[40, 30, 50, 30]\n", - "\n", - "# Add data to create cumulative stacked values\n", - "y0_stck=y0_org\n", - "y1_stck=[y0+y1 for y0, y1 in zip(y0_org, y1_org)]\n", - "y2_stck=[y0+y1+y2 for y0, y1, y2 in zip(y0_org, y1_org, y2_org)]\n", - "\n", - "# Make original values strings and add % for hover text\n", - "y0_txt=[str(y0)+'%' for y0 in y0_org]\n", - "y1_txt=[str(y1)+'%' for y1 in y1_org]\n", - "y2_txt=[str(y2)+'%' for y2 in y2_org]\n", - "\n", - "trace0 = go.Scatter(\n", - " x=x,\n", - " y=y0_stck,\n", - " text=y0_txt,\n", - " hoverinfo='x+text',\n", + "trace0 = dict(\n", + " x=['Winter', 'Spring', 'Summer', 'Fall'],\n", + " y=['40', '20', '30', '40'],\n", " mode='lines',\n", " line=dict(width=0.5,\n", - " color='rgb(131, 90, 241)'),\n", - " fill='tonexty'\n", + " color='rgb(184, 247, 212)'),\n", + " stackgroup='one',\n", + " groupnorm='percent'\n", ")\n", - "trace1 = go.Scatter(\n", - " x=x,\n", - " y=y1_stck,\n", - " text=y1_txt,\n", - " hoverinfo='x+text',\n", + "trace1 = dict(\n", + " x=['Winter', 'Spring', 'Summer', 'Fall'],\n", + " y=['50', '70', '40', '60'],\n", " mode='lines',\n", " line=dict(width=0.5,\n", " color='rgb(111, 231, 219)'),\n", - " fill='tonexty'\n", + " stackgroup='one'\n", ")\n", - "trace2 = go.Scatter(\n", - " x=x,\n", - " y=y2_stck,\n", - " text=y2_txt,\n", - " hoverinfo='x+text',\n", + "trace2 = dict(\n", + " x=['Winter', 'Spring', 'Summer', 'Fall'],\n", + " y=['70', '80', '60', '70'],\n", " mode='lines',\n", " line=dict(width=0.5,\n", - " color='rgb(184, 247, 212)'),\n", - " fill='tonexty'\n", + " color='rgb(127, 166, 238)'),\n", + " stackgroup='one'\n", ")\n", - "data = [trace0, trace1, trace2]\n", - "\n", - "fig = go.Figure(data=data)\n", - "py.iplot(fig, filename='stacked-area-plot-hover')" + "trace3 = dict(\n", + " x=['Winter', 'Spring', 'Summer', 'Fall'],\n", + " y=['100', '100', '100', '100'],\n", + " mode='lines',\n", + " line=dict(width=0.5,\n", + " color='rgb(131, 90, 241)'),\n", + " stackgroup='one'\n", + ")\n", + "data = [trace0, trace1, trace2, trace3]\n", + "layout = go.Layout(\n", + " showlegend=True,\n", + " xaxis=dict(\n", + " type='category',\n", + " ),\n", + " yaxis=dict(\n", + " type='linear',\n", + " range=[1, 100],\n", + " dtick=20,\n", + " ticksuffix='%'\n", + " )\n", + ")\n", + "fig = dict(data=data, layout=layout)\n", + "py.iplot(fig, filename='stacked-area-plot-norm', validate=False)" ] }, { @@ -357,7 +333,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -369,7 +345,7 @@ "" ] }, - "execution_count": 10, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -432,7 +408,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -464,28 +440,18 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to c:\\users\\branden\\appdata\\local\\temp\\pip-l82uyn5e-build\n", + " Cloning https://github.com/plotly/publisher.git to /tmp/pip-req-build-ewWF0_\n", + "Building wheels for collected packages: publisher\n", + " Running setup.py bdist_wheel for publisher ... \u001b[?25ldone\n", + "\u001b[?25h Stored in directory: /tmp/pip-ephem-wheel-cache-zaYWOc/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.11\n", " Uninstalling publisher-0.11:\n", " Successfully uninstalled publisher-0.11\n", - " Running setup.py install for publisher: started\n", - " Running setup.py install for publisher: finished with status 'done'\n", - "Successfully installed publisher-0.11\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\Users\\Branden\\Anaconda3\\envs\\ipykernel_py2\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning:\n", - "\n", - "The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead.\n", - "\n", - "C:\\Users\\Branden\\Anaconda3\\envs\\ipykernel_py2\\lib\\site-packages\\publisher\\publisher.py:53: UserWarning:\n", - "\n", - "Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", - "\n" + "Successfully installed publisher-0.11\n", + "\u001b[33mYou are using pip version 10.0.1, however version 18.0 is available.\n", + "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n" ] } ], @@ -534,9 +500,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.12" + "version": "2.7.15rc1" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 2 } diff --git a/_posts/r/basic/2015-07-30-filled-area-plots.Rmd b/_posts/r/basic/2015-07-30-filled-area-plots.Rmd index 33c482fa2120..69ccf7166da3 100644 --- a/_posts/r/basic/2015-07-30-filled-area-plots.Rmd +++ b/_posts/r/basic/2015-07-30-filled-area-plots.Rmd @@ -265,7 +265,7 @@ library(plotly) data <- t(USPersonalExpenditure) data <- data.frame("year"=rownames(data), data) -p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>% +p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', stackgroup = 'one', fillcolor = '#F5FF8D') %>% add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>% add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>% add_trace(y = ~Personal.Care, name = 'Personal Care', fillcolor = '#700961') %>% @@ -292,15 +292,9 @@ chart_link library(plotly) data <- t(USPersonalExpenditure) -data2 <- data/rowSums(data)*100 -data2 <- data.frame("year"=rownames(data2), data2) - -# Transforming into a cumulative table: -for (i in c(6:3)) { - data2[,i-1] <- data2[,i-1] + data2[,i] -} +data <- data.frame("year"=rownames(data), data) -p <- plot_ly(data2, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>% +p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', stackgroup = 'one', groupnorm = 'percent', fillcolor = '#F5FF8D') %>% add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>% add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>% add_trace(y = ~Personal.Care, name = 'Personal Care', fillcolor = '#700961') %>% diff --git a/_posts/r/basic/2015-07-30-filled-area-plots.md b/_posts/r/basic/2015-07-30-filled-area-plots.md index 821ea4a308e9..9356af9ee1fd 100644 --- a/_posts/r/basic/2015-07-30-filled-area-plots.md +++ b/_posts/r/basic/2015-07-30-filled-area-plots.md @@ -33,7 +33,7 @@ packageVersion('plotly') ``` ``` -## [1] '4.7.1.9000' +## [1] '4.8.0' ``` ### Basic Filled Area Plot @@ -57,7 +57,7 @@ chart_link = api_create(p, filename="area-basic") chart_link ``` - + ### Filled Area Plot with Multiple Traces @@ -84,7 +84,7 @@ chart_link = api_create(p, filename="area-basic2") chart_link ``` - + ### Selecting Hover Points @@ -141,7 +141,7 @@ chart_link = api_create(p, filename="area-hoveron") chart_link ``` - + ### Custom Colors @@ -169,7 +169,7 @@ chart_link = api_create(p, filename="area-colors") chart_link ``` - + ### Area Plot without Lines @@ -198,7 +198,7 @@ chart_link = api_create(p, filename="area-nolines") chart_link ``` - + ### Interior Filling for Area Chart @@ -250,7 +250,7 @@ chart_link = api_create(p, filename="area-interior") chart_link ``` - + ### Stacked Area Chart with Original Values @@ -261,7 +261,7 @@ library(plotly) data <- t(USPersonalExpenditure) data <- data.frame("year"=rownames(data), data) -p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>% +p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', stackgroup = 'one', fillcolor = '#F5FF8D') %>% add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>% add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>% add_trace(y = ~Personal.Care, name = 'Personal Care', fillcolor = '#700961') %>% @@ -278,7 +278,7 @@ chart_link = api_create(p, filename="area-stackedoriginal") chart_link ``` - + ### Stacked Area Chart with Cumulative Values @@ -287,15 +287,9 @@ chart_link library(plotly) data <- t(USPersonalExpenditure) -data2 <- data/rowSums(data)*100 -data2 <- data.frame("year"=rownames(data2), data2) - -# Transforming into a cumulative table: -for (i in c(6:3)) { - data2[,i-1] <- data2[,i-1] + data2[,i] -} +data <- data.frame("year"=rownames(data), data) -p <- plot_ly(data2, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', fill = 'tozeroy', fillcolor = '#F5FF8D') %>% +p <- plot_ly(data, x = ~year, y = ~Food.and.Tobacco, name = 'Food and Tobacco', type = 'scatter', mode = 'none', stackgroup = 'one', groupnorm = 'percent', fillcolor = '#F5FF8D') %>% add_trace(y = ~Household.Operation, name = 'Household Operation', fillcolor = '#50CB86') %>% add_trace(y = ~Medical.and.Health, name = 'Medical and Health', fillcolor = '#4C74C9') %>% add_trace(y = ~Personal.Care, name = 'Personal Care', fillcolor = '#700961') %>% @@ -313,7 +307,7 @@ chart_link = api_create(p, filename="area-stackedcum") chart_link ``` - + #Reference