Loading...
 
Skip to main content

History: Profile_r_test7_plot.ly

Source of version: 8

Copy to clipboard
            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: 
* http://timelyportfolio.blogspot.com.es/2013/04/d3-r-with-rcharts-and-slidify.html
* http://timelyportfolio.github.io/rCharts_512paths/

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

# 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["CRAN"] <- "http://ftp.heanet.ie/mirrors/cran.r-project.org/"
options(repos=r)
# Update packages first
update.packages(ask = FALSE, repos = 'http://cran.rstudio.org')

# 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

# get data from downloaded NYT tsv and inject in through params
# 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' )
# If you are in multitiki, jump 3 directories for the directory to save the files
unzip('rCharts_512paths.zip', exdir = '../../../public/')
# Alternatively, jump just two.
#unzip('rCharts_512paths.zip', exdir = '../../public/')

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

# 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)
# We have to fix some relative path which seems to be wrong for its equivalent absolute path
p1$LIB[2] <- paste("http://{{domain}}/temp/public/rCharts_512paths-gh-pages", "/", p1$lib, sep="")
p1$templates$script <- paste(p1$LIB[2], p1$templates$script, sep="")
# 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. 
# Path, by default, is the working directory
#p1
p1$save('mychart.html')
{RR}

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

{CODE()}
{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"}
{CODE}

{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"}

        

History

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