Plotly Beta: Collaborative Plotting with R

December 16, 2013

(This article was first published on R-statistics blog » R, and kindly contributed to R-bloggers)

(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!


To leave a comment for the author, please follow the link and comment on their blog: R-statistics blog » R. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Recent popular posts


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Dommino data lab

Quantide: statistical consulting and training



CRC R books series

Six Sigma Online Training

Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)