Overwriting, Extending, Appending, and Creating New Graphs in R

Creating new files

library(plotly)
p <- plotly(username='rAPI', key='yu680v5eii')

p$plotly(c(1,2), c(3,4),
	kwargs=list(filename='new plot',
	fileopt='new'))

API RESPONSE:

$url
[1] "https://plot.ly/~demos/1058"
$message
[1] ""
$warning
[1] ""
$filename
[1] "new plot"
$error
[1] ""
library(plotly)
p <- plotly(username='rAPI', key='yu680v5eii')

p$plotly(c(1,2), c(3,4),
	kwargs=list(filename='new plot',
	fileopt='new'))
Check out the filename and url in the responses. We specified the same filename in both calls, but since we used the fileopt 'new', our second call appended '(1)' to the filename and created a new unique url for that graph. The first graph was not overwritten.

API RESPONSE:

$url
[1] "https://plot.ly/~demos/1059"
$message
[1] ""
$warning
[1] ""
$filename
[1] "new plot (1)"
$error
[1] ""

Overwriting existing files

The overwrite option will save the plot with the specified filename no matter what. If a plot already exists under the same name, it will overwrite it and create a revision. If the plot with that filename doesn't exist, it will create it!
library(plotly)
p <- plotly(username='rAPI', key='yu680v5eii')

p$plotly(c(1,2), c(3,4),
	kwargs=list(filename='same plot',
	fileopt='overwrite'))

API RESPONSE:

$url
[1] "https://plot.ly/~demos/1055"
$message
[1] ""
$warning
[1] ""
$filename
[1] "same plot"
$error
[1] ""
library(plotly)
p <- plotly(username='rAPI', key='yu680v5eii')

p$plotly(c(10,20), c(30,40),
	kwargs=list(filename='same plot',
	fileopt='overwrite'))

API RESPONSE:

$url
[1] "https://plot.ly/~demos/1055"
$message
[1] ""
$warning
[1] ""
$filename
[1] "same plot"
$error
[1] ""

Extending existing traces

The "extend" fileopt will extend existing traces with your new data.
library(plotly)
p <- plotly(username='rAPI', key='yu680v5eii')

p$plotly(c(1,2), c(1,2), c(1,2), c(2,3), c(1,2), c(3,4),
	kwargs=list(filename='extend plot',
	fileopt='extend'))
If there is no data in the plot, 'extend' will create new traces.
library(plotly)
p <- plotly(username='rAPI', key='yu680v5eii')

p$plotly(c(3,4), c(2,1), c(3,4), c(3,2), c(3,4), c(4,3),
	kwargs=list(filename='extend plot',
	fileopt='extend'))
If there is data in the plot, the existing traces will be extended with the data in the order that it is supplied.

Adding new traces

The "append" fileopt will append the data that you supplied as new traces. If the filename doesn't exist, it will create a new file with that data.
library(plotly)
p <- plotly(username='rAPI', key='yu680v5eii')

p$plotly(c(1,2), c(1,2),
	kwargs=list(filename='append plot',
	fileopt='append'))
Here we're starting with one trace.
library(plotly)
p <- plotly(username='rAPI', key='yu680v5eii')

p$plotly(c(1,2), c(3,4),
	kwargs=list(filename='append plot',
	fileopt='append'))
Here we are appending a new trace with points (1,3) and (2,4).
library(plotly)
p <- plotly(username='rAPI', key='yu680v5eii')

p$plotly(c(1,2), c(4,5), c(1,2), c(5,6),
	kwargs=list(filename='append plot',
	fileopt='append'))
Here we are appending two new traces at points (1,4), (2,5) and (1,5), (2,6).