Plot.ly Charts using PluginR and Tiki
Derived from
http://www.r-statistics.com/2013/12/plotly-beta-collaborative-plotting-with-r/
See
https://plot.ly/
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.
{RR(echo="0", cacheby="pagename", wikisyntax="0")}
# Installing Plotly
# -----------------------
# 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/") }
# Next, install plotly (a big thanks to Hadley, who suggested the GitHub route):
if(!require(plotly)){ devtools::install_github("plotly/R-api") }
# ...
# * DONE (plotly)
# 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')
# You'll get as output in the R console:
#
## Thanks for signing up to plotly!
##
## Your username is: yournewusername
##
## Your temporary password is: yourtemppassword. You use this to log into your plotly account at https://plot.ly/plot.
##
## 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="yournewusername", 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:
# ------------------------
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/"}