Loading...
 

Profile_r_test9_rcharts_512paths

Testing a nice interactive graph created with rCharts & d3, with data from x512paths: NY Times 512 Paths to the White House.
Recreated in R with rCharts and slidify.

For more information, see:

{RR(echo="1" cacheby="pagename")}
  1. Testing rCharts & d3, from http://timelyportfolio.blogspot.com.es/2013/04/d3-r-with-rcharts-and-slidify.html

  1. Set a mirror, in case the required packages have dependencies, and those dependencies do not indicate which mirror to install the package from.
r <- getOption("repos")
r%22CRAN%22 <- "http://ftp.heanet.ie/mirrors/cran.r-project.org/"
options(repos=r)
  1. Update packages first
update.packages(ask = FALSE, repos = 'http://cran.rstudio.org')

  1. if you have not installed slidify, slidifyLibraries, or rCharts
if(!require(devtools)){ install.packages("devtools", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") }
require('devtools', quietly = TRUE )
if(!require(slidify)){ install_github('slidify', 'ramnathv', ref = 'dev') }
require(slidify, quietly = TRUE)
if(!require(rCharts)){ install_github('rCharts', 'ramnathv') }
if(!require(codetools)){ install.packages("codetools", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") }
require(codetools, quietly = TRUE )
if(!require(slidifyLibraries)){ install_github('slidifyLibraries', 'ramnathv', ref = 'dev') } # optional

  1. get data from downloaded NYT tsv and inject in through params
  2. download repo and unzip to Downloads folder
if(!require(downloader)){ install.packages("downloader", repos="http://ftp.heanet.ie/mirrors/cran.r-project.org/") }
require(downloader, quietly = TRUE )
download( 'https://github.com/timelyportfolio/rCharts_512paths/archive/gh-pages.zip', 'rCharts_512paths.zip' )
  1. If you are in multitiki, jump 3 directories for the directory to save the files
unzip('rCharts_512paths.zip', exdir = '../../../public/')
  1. Alternatively, jump just two.
  2. unzip('rCharts_512paths.zip', exdir = '../../public/')

  1. Set the working directory
  2. If you are in multitiki, jump 3 directories
setwd('../../../public/rCharts_512paths-gh-pages')
  1. Alternatively, jump just two.
  2. setwd('../../public/rCharts_512paths-gh-pages')

  1. plot the data
require(rCharts, quietly = TRUE )
data <- read.delim(file = "data/states.tsv")
p1 <- rCharts$new()
getwd();
p1$field("lib", "libraries/widgets/x512paths")
p1$set(data = toJSONArray(data), dom = NULL)
  1. We have to fix some relative path which seems to be wrong for its equivalent absolute path
p1$LIB2 <- paste("http://{{domain}}/temp/public/rCharts_512paths-gh-pages", "/", p1$lib, sep="")
p1$templates$script <- paste(p1$LIB2, p1$templates$script, sep="")
  1. Here we don't create the chart on the fly with a random page name in an uncontroled directory server side, but instead, we save the p1 object as html page ni a defined-by-us path & filename.
  2. Path, by default, is the working directory
  3. p1
p1$save('mychart.html')
{RR}

Now we show the chart in this wiki page through an iframe:

{iframe name="myChart" width="1000" height="1200" align="middle" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" src="temp/public/rCharts_512paths-gh-pages/mychart.html"}


Plugin execution pending approval

This plugin was recently added or modified. Until an editor of the site validates the parameters, execution will not be possible.