Loading...
 

History: Profile_r_test7_plot.ly

Preview of version: 12

Plot.ly Charts using PluginR and Tiki

Derived from http://www.r-statistics.com/2013/12/plotly-beta-collaborative-plotting-with-r/
See

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.

Page contents


Installing Plotly

{CODE(ln="1", colors="r")}
{RR(echo="0", cacheby="pagename", wikisyntax="0")}
  1. Installing Plotly
  2. -----------

  1. Install de required packages if you don't have them yet
if(!require(devtools)){ install.packages("devtools", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") }
require("devtools")
if(!require(RCurl)){ install.packages("RCurl", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") }
if(!require(bitops)){ install.packages("bitops", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") }
if(!require(RJSONIO)){ install.packages("RJSONIO", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") }

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

if(!require(plotly)){ devtools::install_github("plotly/R-api") }

  1. ...
  2. * DONE (plotly)

  1. Then sign-up like this (adapt username and email to your choice) or at https://plot.ly/:
require(plotly)
response = signup (username = 'yournewusername', email= 'youremail@example.com')

  1. You'll get as output in the R console:
    1. Thanks for signing up to plotly!
    2. Your username is: yournewusername
    3. Your temporary password is: yourtemppassword. You use this to log into your plotly account at https://plot.ly/plot.
    4. Your API key is: API_Key. You use this to access your plotly account through the API.
    5. To get started, initialize a plotly object with your username and api_key, e.g.
    6. >>> p <- plotly(username="yournewusername", key="API_Key")
    7. Then, make a graph!
    8. >>> res <- p$plotly(c(1,2,3), c(4,2,1))

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

Overlaid Histograms

{RR(echo="0", cacheby="pagename", wikisyntax="0")} # 1. Overlaid Histograms: # ------------------------ require(plotly) p <- plotly(username="yournewusername", key="API_Key") x0 = rnorm(500) x1 = rnorm(500)+1 data0 = list(x=x0, type='histogramx', opacity=0.8) data1 = list(x=x1, type='histogramx', opacity=0.8) 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. #browseURL(response$url) # In Tiki, you can plot the graph in a wiki page by means of an iframe to the reponse$url # #cat(response$url) # # But since Tiki doesn't allow the word "url" in scripts, we will use the index of the value in the response list: cat(unlist(response[1])) cat(unlist(response[1]) ) # This will produce something like: # #"https://plot.ly/~yournewusername/0/" # # Then you just need to include that url in an iframe as usual in Tiki {RR} {iframe name=myPlotlyChart width=800 height=600 align=middle frameborder=0 marginheight=0 marginwidth=0 scrolling=auto src="https://plot.ly/~yournewusername/0/"}




Log-normal Boxplot

{RR(echo="1", cacheby="pagename", wikisyntax="0")} # 2. Log-normal Boxplot # ------------------------ require(plotly) 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)) #browseURL(response$url) # Again, in Tiki, you can plot the graph in a wiki page by means of an iframe to the reponse$url = unlist(response[1]) {RR} {iframe name=myPlotlyChart width=800 height=600 align=middle frameborder=0 marginheight=0 marginwidth=0 scrolling=auto src="https://plot.ly/~ueb/14/"}




More types of charts...

For more examples of chart types possible with Plot.ly and R, see:

Collaborating and Sharing

# Collaborating and Sharing: You’re in Control # --------------------------------------------- # # Keep in mind that: # # (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.

History

Advanced
Information Version
Mon 23 of Dec, 2013 20:05 GMT-0000 Xavier de Pedro added example of heatmaps 14
Mon 23 of Dec, 2013 17:21 GMT-0000 Xavier de Pedro fixing rr section 13
Thu 19 of Dec, 2013 11:57 GMT-0000 Xavier de Pedro more examples 12
Thu 19 of Dec, 2013 11:39 GMT-0000 Xavier de Pedro new url 11
Thu 19 of Dec, 2013 11:37 GMT-0000 Xavier de Pedro added info about sharing with plot.ly 10
Thu 19 of Dec, 2013 11:25 GMT-0000 Xavier de Pedro changed for plot.ly based charts 9
Thu 19 of Dec, 2013 00:21 GMT-0000 Xavier de Pedro added some extra check 8
Wed 18 of Dec, 2013 14:36 GMT-0000 Xavier de Pedro updated 7
Wed 18 of Dec, 2013 14:33 GMT-0000 Xavier de Pedro changed chart 6
Fri 11 of Oct, 2013 09:28 GMT-0000 Xavier de Pedro fixed iframe src path for Tiki12 5
Fri 31 of May, 2013 10:09 GMT-0000 Xavier de Pedro replaced some explicit code sections with the param echo=1 4
Sat 25 of May, 2013 12:22 GMT-0000 Xavier de Pedro added lattice 3
Fri 10 of May, 2013 15:21 GMT-0000 Xavier de Pedro updated 2nd chart 2
Fri 10 of May, 2013 15:20 GMT-0000 Xavier de Pedro first version 1