Plotly Beta: Collaborative Plotting with R

[This article was first published on R-statistics blog » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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


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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)