Plotly Beta: Collaborative Plotting with R

(Guest post by Matt Sundquist on a lovely new service which is pro-actively supporting an API for R)

The Plotly R graphing library  allows you to create and share interactive, publication-quality plots in your browser. Plotly is also built for working together, and makes it easy to post graphs and data publicly with a URL or privately to collaborators.

In this post, we’ll demo Plotly, make three graphs, and explain sharing. As we’re quite new and still in our beta, your help, feedback, and suggestions go a long way and are appreciated. We’re especially grateful for Tal’s help and the chance to post.

Installing Plotly

Sign-up and Install (more in documentation)

From within the R console:


Next, install plotly (a big thanks to Hadley, who suggested the GitHub route):

# ...
# * DONE (plotly)

Then sign-up like this or at

>response = signup (username = 'username', email= 'youremail')
Thanks for signing up to plotly!

Your username is: MattSundquist

Your temporary password is: pw. You use this to log into your plotly account at Your API key is: “API_Key”. You use this to access your plotly account through the API.

To get started, initialize a plotly object with your username and api_key, e.g.
>>> p <- plotly(username="MattSundquist", key="API_Key")
Then, make a graph!
>>> res <- p$plotly(c(1,2,3), c(4,2,1))

And we’re up and running! You can change and access your password and key in your homepage.

1. Overlaid Histograms:

Here is our first script.

p <- plotly(username="USERNAME", key="API_Key")

x0 = rnorm(500)
x1 = rnorm(500)+1
data0 = list(x=x0,
data1 = list(x=x1,
layout = list(barmode='overlay')

response = p$plotly(data0, data1, kwargs=list(layout=layout))


The script makes a graph. Use the RStudio viewer or add “browseURL(response$url)” to your script to avoid copy and paste routines of your URL and open the graph directly.


Press “Save a Copy” to start styling from the GUI. So, find out “how would this look if I tweaked...,” or “what if I tweaked [element of graph I love to obsess over]?”


Plotly supports line charts, scatter plots, bubble charts, histograms, 2D histograms, box plots, heatmaps, and error bars. We also support log axes, date axes, multiple axes, subplots, and LaTeX. Or, analyze your data:


You can also embed your URL into this snippet to make an iframe (e.g., this Washington Post piece). You can adjust the width and height.

<iframe id="igraph" src="" width="400" height="250" seamless="seamless" scrolling="no"></iframe>


2. Heatmap


p <- plotly(username='USERNAME', key='API_KEY')

zd <- matrix(rep(runif(38,0,38),26),26)

#random.sample(range(0, 41),41) for j in range(8)]
z <- tapply(z,(rep(1:nrow(z),ncol(z))),function(i)list(i))

cs <- list(

data <- list(
    z = zd,
    scl = cs,
    type = 'heatmap'

response <- p$plotly(data)


3. Log-normal Boxplot


p <- plotly(username='USERNAME', key='API_KEY')

x <- c(seq(0,0,length=1000),seq(1,1,length=1000),seq(2,2,length=1000))
y <- c(rlnorm(1000,0,1),rlnorm(1000,0,2),rlnorm(1000,0,3))
s <- list(
    type = 'box',
    jitter = 0.5
layout <- list(
    title = 'Fun with the Lognormal distribution',
    yaxis = list(
        type = 'log'

response <- p$plotly(x,y, kwargs = list(layout = layout, style=s))


Collaborating and Sharing: You’re in Control

Nicola Sommacal posted about Plotly this week, which we thoroughly appreciate. He mentioned privacy, and we wanted to make sure we highlighted:

(1) You control if graphs are public or private, and who you share with (like Google Docs)

(2) Public sharing in Plotly is free (like GitHub).

To share privately, press “Share” in our GUI or share with your script. Users you share with get an email and can edit and comment on graphs. That means no more emailing data, graphs, screenshots, and spreadsheets around: you can do it all in Plotly. You can also save and apply custom themes to new data to avoid re-making the same graphs with new data. Just upload and apply your theme.

We would love to see your examples and hear your feedback. You can email our team at [email protected], or connect with us on Twitter or Facebook.

Click here to see the graphs and code for our gallery. Happy plotting!


11 thoughts on “Plotly Beta: Collaborative Plotting with R”

  1. Thanks for the brief tutorial.
    I find a problem: You say “Use the RStudio viewer”, but the RStudio viewer
    can only be used for local html files and plotly creates the files on the server (which
    has advantages and disadvantages). This is actually in the 4th line of the link you provide.

    1. Thanks for checking it out! And you’re correct; I should have been more specific. You can use the RStudio viewer to serve Plotly graphs if you’re paying for an RStudio server. The free version currently does not allow for live web-content in the viewer.

      We’ve talked with the RStudio team a bit, and they indicated a future plan to sandbox their viewer, in which case it would be straightforward to show live graphs from the web in an iframe in the Viewer. That’s what we do with IPython, and what we aspire to do with RStudio. You can see an IPython Notebook running R here where we directly server graphs into an iframe:

      That’s the dream for RStudio!

      If you want to email me at matt at plot dot ly, I’ll keep you updated on this one. Feel free to contact their team too, as they are super helpful and friendly. And I suspect it means more for them hearing from someone besides use 🙂 .

      On the topic of integration with useful R tools, we have been able to get Plotly graphs into RPubs, which you can see here and replicate if you go to the source: Also, you can put Plotly graphs into Shiny apps:

    1. HI Jeffery,
      I assume it does. (at least the data needed for the plot itself, I assume no more – but you should search their about pages and privacy statements)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.