R

R

R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization and general computing. Provide minimal, reproducible, representative example(s) along with the desired end result.
Nat  Grady

Nat Grady

1664349960

VivagRaph: R Package for interactive Network Plots using VivaGraph js

VivagRaph

R package for interactive network plots using VivaGraph js. Built with htmlwidgets.

Example Use

Nodes = data.frame(nodeName=c('Homer','Bart','Lisa','Milhouse','Lenny'), group=c(1,1,1,2,3))
Edges = data.frame(source=c(0,1,0,1,0),target=c(1,2,2,3,4))
vivagRaph(nodes=Nodes,edges=Edges)

Example Network

Installation

devtools::install_github('keeganhines/vivagRaph')
library(vivagRaph)

Download Details:

Author: Keeganhines/
Source Code: https://github.com/keeganhines/vivagRaph 

#r #network #interactive #javascript 

VivagRaph: R Package for interactive Network Plots using VivaGraph js
Nat  Grady

Nat Grady

1664346000

An R Htmlwidget interface to The TauCharts Javascript Library

Taucharts is an R htmlwidget interface to the TauCharts javascript library

Take a look at the TODO list and chip in!

Right now, you can make & customize (including manual color scales & ordered factors + legends + tooltips + trendlines):

  • scatterplots
  • scatterplot matrices
  • line charts
  • bar charts (veritical, horizontal & stacked)

Composite plots are on the road map for support but not in the R package yet.

Have a look on RPubs to see what taucharts can do!

The following functions are implemented:

  • tauchart: Create a new TauChart
  • tau_line: Create a TauCharts line chart
  • tau_point: Create a TauCharts scatterplot
  • tau_bar: Create a TauCharts bar chart (horizontal or vertical)
  • tau_stacked_bar: Create a TauCharts stacked bar chart (veritcal only)
  • tau_guide_gridlines: Control showing of axis gridlines
  • tau_guide_padding: Set overall chart padding
  • tau_guide_x: Control x-axis padding, label, scale & tick format
  • tau_guide_y: Control y-axis padding, label, scale & tick format
  • tau_legend: Add a TauCharts legend
  • tau_tooltip: Add a TauCharts tooltip
  • tau_trendline: Add a TauCharts trendline
  • run_tau_app: Run a built-in example Shiny app
  • tau_tasks: Add post-render JavaScript tasks to taucharts
  • tau_add_css_rule: Add a CSS rule to the rendered htmlwidget
  • tau_set_font: Set font-family for the chart
  • as_tauchart: Turn a simple (single-geom) ggplot plot into an tauchart object
  • tau_title: Add a title to the tauchart plot

with many color palette options:

  • tau_color_manual: Specify the colors used in the charts
  • tau_color_brewer: Use the ColorBrewer palette in the charts
  • tau_color_economist: Use the “Economist” palette used in the charts
  • tau_color_few: Use the “Few” palette used in the charts
  • tau_color_highcharts: Use the HighchartsJS palette used in the charts
  • tau_color_manual: Specify the colors used in the charts
  • tau_color_tableau: Use the Tableau palette in the charts
  • tau_color_wsj: Use the “Wall Street Journal” palette used in the charts

The following datasets are included:

  • cars_data: statistics on cars released from 1997 through 2013 (a data frame with 135 rows and 7 variables)

News

  • Version 0.4.5 released : Shiny click events, color themes for faceted charts, updated TauCharts JS lib
  • Version 0.4.4.9000 released : tau_title
  • Version 0.4.3.9000 released : minor issue with guides
  • Version 0.4.2.9000 released : pre-CRAN flight check
  • Version 0.4.0.9000 released : added as_tauchart & updated TauCharts JS lib
  • Version 0.3.4.9000 released : added warning for global targeted CSS rules and font ref fix thx to @jlewis91
  • Version 0.3.3.9001 released : fix for custom colors and tau_line
  • Version 0.3.3 released : custom font for chart (?tau_set_font)
  • Version 0.3.2 released : custom colors working in legend & trendlines
  • Version 0.3.1 released : removed R 3.2.0 dependency (removed the dependent code)
  • Version 0.3.0 released : color palettes galore!
  • Version 0.3.0.9000 released : ?tau_add_css_rule (add CSS rules to a chart)
  • Version 0.2.6.9000 released : ?tau_tasks (add JavaScript to a chart)
  • Version 0.2.5.9000 released : list & run example Shiny apps - see ?run_tau_app for more info
  • Version 0.2.5.9000 released : stacked bar charts
  • Version 0.1.0 released : trendline, tooltips & dev fork (prod is pretty much stable & functional)
  • Version 0.0.1.9003 released : facet-based ordering + legends
  • Version 0.0.1.9000 released : auto-detects column classes, can add manual colors & faceted plots are now working (see the Rpub for an example)
  • Version 0.0.0.9000 released

Installation

devtools::install_github("hrbrmstr/taucharts")

Usage

library(taucharts)

# current verison
packageVersion("taucharts")
#> [1] '0.4.5'

Test Results

library(testthat)
date()
#> [1] "Fri May 11 00:02:12 2018"

test_dir("tests/testthat", reporter = SummaryReporter)
#> basic functionality: S
#> 
#> ══ Skipped ════════════════════════════════════════════════════════════════════════════
#> 1. we can do something (@test-taucharts.R#2) - Empty test
#> 
#> ══ DONE ═══════════════════════════════════════════════════════════════════════════════

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Download Details:

Author: Hrbrmstr
Source Code: https://github.com/hrbrmstr/taucharts 
License: View license

#r #charts #javascript 

An R Htmlwidget interface to The TauCharts Javascript Library
Nat  Grady

Nat Grady

1664338560

D3 Coffee Wheel Visualization Ported to R Via Htmlwidgets Framework

An R Interface to D3-based Coffee Wheel

This is an htmlwidgets-based visualization tool for hierarchical data. It is zoomable, meaning that you can interact with the hierarchy and zoom in/out accordingly. 

Enjoy!

Install

This package is currently not on CRAN, but you can install it from GitHub via devtools:

library("devtools");
devtools::install_github("armish/coffeewheel");

Sample Plotting

library("coffeewheel");
coffeewheel(sampleWheelData, width=500, height=500, main="Sample Wheel Title", partitionAttribute="value");

Zoomable Wheel

Sample Data Structure

sampleWheelData <- list(
    list(
        name="R",
        children=list(
            list(name="R_1", colour="#110000"),
            list(name="R_3", colour="#330000"),
            list(name="R_5", colour="#550000"),
            list(name="R_7", colour="#770000"),
            list(name="R_9", colour="#990000"),
            list(name="R_b", colour="#bb0000"),
            list(name="R_d", colour="#dd0000"),
            list(name="R_f", colour="#ff0000")
        )
    ),
    list(
        name="G",
        children=list(
            list(name="G_1", colour="#001100"),
            list(name="G_3", colour="#003300"),
            list(name="G_5", colour="#005500"),
            list(name="G_7", colour="#007700"),
            list(name="G_9", colour="#009900"),
            list(name="G_b", colour="#00bb00"),
            list(name="G_d", colour="#00dd00"),
            list(name="G_f", colour="#00ff00")
        )
    ),
    list(
        name="B",
        children=list(
            list(name="B_1", colour="#000011"),
            list(name="B_3", colour="#000033"),
            list(name="B_5", colour="#000055"),
            list(name="B_7", colour="#000077"),
            list(name="B_9", colour="#000099"),
            list(name="B_b", colour="#0000bb"),
            list(name="B_d", colour="#0000dd"),
            list(name="B_f", colour="#0000ff")
        )
    )
);

Credits

This version of the wheel was adapted from Jason Davies's Coffee Wheel example. Built with D3.js. Sunburst zooming based on an example by Mike Bostock.


The visualization is D3-based and the actual wheel visualization code is adapted from:

https://www.jasondavies.com/coffee-wheel/


Download Details:

Author: Armish
Source Code: https://github.com/armish/coffeewheel 

#r #visualization #3d 

D3 Coffee Wheel Visualization Ported to R Via Htmlwidgets Framework
Nat  Grady

Nat Grady

1664334480

EdgebundleR: Circle Plot with Bundled Edges

Circle plot with bundled edges  

This package allows R users to easily create a hierarchical edge bundle plot. The underlying D3 code was adapted from Mike Bostock's examples (see here or here) and the package is based on the htmlwidgets framework.

Many thanks to timelyportfolio for some major improvements.

example graph

Installation

You can install edgebundleR from Github using the devtools package as follows:

# install.packages("devtools")
devtools::install_github("garthtarr/edgebundleR")

Or you can get it on CRAN:

install.packages("edgebundleR")

Usage

library(edgebundleR)

The main function in the edgebundleR package is edgebundle(). It takes in a variety of inputs:

  • an igraph object
  • a symmetric matrix, e.g. a correlation matrix or (regularised) precision matrix
  • a JSON file structured with name and imports as the keys

The result of the edgebundle() function is a webpage that is rendered in the RStudio Viewer pane by default, but also may be exported to a self contained webpage, embedded in an Rmarkdown document or used in a Shiny web application.

Download Details:

Author: Garthtarr
Source Code: https://github.com/garthtarr/edgebundleR 

#r #edge 

EdgebundleR: Circle Plot with Bundled Edges
Nat  Grady

Nat Grady

1664330520

PairsD3: D3 Scatterplot Matrices

D3 Scatterplot Matrices

This is a port of Mike Bostock's D3 scatter plot matrix code to the htmlwidgets framework. There have been some minor adjustments, including the addition of tooltips.

You could also consider the pairedVis() function in the healthvis package.

Take it for a test run here (you can upload your own data).

Installation

The pairsD3 package is available on CRAN:

install.packages("pairsD3")

Alternatively, you can install the development version of pairsD3 from Github using the devtools package as follows:

devtools::install_github("garthtarr/pairsD3")

Usage

A canonical example with the iris data:

data(iris)
require(pairsD3)
pairsD3(iris[,1:4],group=iris[,5])

Save

Use savePairs to save a pairs plot as a stand alone HTML file:

library(magrittr)
pairsD3(iris[,1:4],group=iris[,5]) %>% savePairs(file = 'iris.html')

Shiny

You can view an interactive scatterplot matrix using the shinypairs function:

shinypairs(iris)

Rmarkdown

You can include interactive scatterplot matrices in rmarkdown documents in the usual way:

```{r}
require(pairsD3)
pairsD3(iris)
```

Slidify

HTML widgets are not (yet) supported in slidify. A workaround is to do save the widget as a webpage then include that webpage in slidify using an iframe:

```{r, results='asis',echo=FALSE}
require(pairsD3)
pd3 = pairsD3(iris)
savePairs(pd3, 'pD3.html')
cat('<iframe src="pD3.html"> </iframe>')
```

Download Details:

Author: Garthtarr/
Source Code: https://github.com/garthtarr/pairsD3 

#r #d3 #scatterplot 

PairsD3: D3 Scatterplot Matrices
Nat  Grady

Nat Grady

1664326560

Bubbles: D3 Bubble Chart for R

D3.js bubble chart htmlwidget for R

This R package provides a bubble chart as seen in this Mike Bostock example. It is based on htmlwidgets so it can be used from the R console, RStudio, R Markdown documents, and Shiny applications.

Installation

Use the devtools package (install.packages("devtools")) to install this package directly from GitHub:

devtools::install_github("jcheng5/bubbles")

Usage

library(bubbles)

bubbles(value = runif(26), label = LETTERS,
  color = rainbow(26, alpha=NULL)[sample(26)]
)

Sample output

See ?bubbles::bubbles for more options. For use with Shiny, see ?bubbles::renderBubbles.

Download Details:

Author: jcheng5
Source Code: https://github.com/jcheng5/bubbles 
License: MIT license

#r #chart #d3 

Bubbles: D3 Bubble Chart for R
Nat  Grady

Nat Grady

1664322600

ScatterMatrixD3: R Htmlwidget Wrapper Around The D3 Scatterplot Matrix

ScatterMatrixD3

R Htmlwidget Wrapper Around The D3 Scatterplot Matrix

This is a htmlwidget wrapper around Benjie Chen's extension of Mike Bostock's scatterplot matrix.

Usage

library(scatterMatrixD3)

scatterMatrix(
   data = iris
)

Download Details:

Author: jcizel
Source Code: https://github.com/jcizel/scatterMatrixD3 

#r #d3 #matrix 

ScatterMatrixD3: R Htmlwidget Wrapper Around The D3 Scatterplot Matrix
Nat  Grady

Nat Grady

1664318160

RWordCloud: An Htmlwidget interface for D3 Word Cloud

rWordCloud - An htmlwidget interface to D3 word cloud

to install

require(devtools)
install_github('adymimos/rWordCloud')

d3TextCloud - Pass compelete sentence, Java script calculates word count It performs stemming and stop word removals

d3Cloud - Pass word and its size

d3TextCloud
server.R
library(rWordCloud)
function(input, output, session) {
output$d3TextCloud <- renderd3TextCloud({
   content <- c('test test1 test2 hi ho hurray hi hurray ho ho ho ho','ho hi uh ho','test')
   label <- c('a1','a2','a3')
   d3TextCloud(content = content, label = label)
  })
}

ui.R

library(rWordCloud)
fluidPage(
d3TextCloudOutput("d3TextCloud", width = "100%", height = 500)
)

output alt tag

d3Cloud
library(rWordCloud)
function(input, output, session) {
  output$d3Cloud <- renderd3Cloud({
   text <- c('d3','wordcloud','impressive','experiment','htmlwidgets','myfirstwidget')
   size <- c(25,20,13,9,6,5)
   df <- data.frame(text,size)
   d3Cloud(text = text, size = size)
  })
}



ui.R
library(solrCloud)
fluidPage(
d3CloudOutput("d3Cloud", width = "100%", height = 500)
)

Example from shiny gallery using rWordCloud - https://github.com/rstudio/shiny-examples/tree/master/082-word-cloud alt tag code - https://github.com/adymimos/rWordCloud/tree/master/inst/examples/shiny/ex2/

Interactive example - input$d3word gives you the word selected from the UI. alt tag code - https://github.com/adymimos/rWordCloud/tree/master/inst/examples/shiny/ex3/

More info in my blog - http://bigdataanalyze.blogspot.com/2015/02/rwordcloud-htmlwidget-interface-for-d3.html

Download Details:

Author: Adymimos
Source Code: https://github.com/adymimos/rWordCloud 
License: View license

#r #d3 #cloud #javascript 

RWordCloud: An Htmlwidget interface for D3 Word Cloud
Nat  Grady

Nat Grady

1664314020

A Successful Attempt to Create Great Circles Arcs Via D3, Shiny and R

great-circles

An attempt to create great circles arcs via d3, Shiny, htmlwidgets and R.

Pull the repo, and type devtools::install() to get your nice great circle widget. Or you can devtools::install_github("homeaway/great-circles") and get it directly.

To use, create a data.frame with four columns and call the greatCircles function.

library(greatCircles)

greatCircles(data.frame(
  longitude.start=c(-0.1015987,9.9278215,2.3470599,12.5359979,-42.9232368,114.1537584,
                    139.7103880,-118.4117325,-73.9796810,4.8986142,7.4259704,-1.7735460),
  latitude.start = c(51.52864,53.55857,48.85886,41.91007,-22.06645,22.36984,35.67334,
                     34.02050,40.70331,52.37472,43.74105,52.49033),
  longitude.finish = c(9.9278215,2.3470599,12.5359979,-42.9232368,114.1537584,139.7103880,
                       -118.4117325,-73.9796810,4.8986142,7.4259704,-1.7735460,-0.1015987),
  latitude.finish = c(53.55857,48.85886,41.91007,-22.06645,22.36984,35.67334,34.02050,
                      40.70331,52.37472,43.74105,52.49033,51.52864)
))

What works:

inst/examples/standalone-example.R 

This will/should display a tour all over the world. Looks like this:

world-plot

Running inside of Shiny works as well.

inst/examples/shiny-example.R

Arc styling is controlled via CSS:

/* styles the land elements (countries) */
.land {
  fill: #333333;
}

/* border between countries */
.boundary {
  fill: none;
  stroke: #111111;
  stroke-width: .5px;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* arc styling */
.arc {
  fill: none;
  stroke: #FED863;  /*homeaway yellow*/
  stroke-width: 1.5px;
  stroke-linecap: round;
  stroke-opacity: 0.3;
}

/* arc:hover styling */
.arc:hover {
  stroke: #2A6EBB; /*homeaway blue*/
  stroke-width: 5px;
  stroke-opacity: 1.0;
}

Copyright (c) 2015 HomeAway.com

Download Details:

Author: Homeaway
Source Code: https://github.com/homeaway/great-circles 
License: View license

#r #d3 #javascript 

A Successful Attempt to Create Great Circles Arcs Via D3, Shiny and R
Nat  Grady

Nat Grady

1664310000

HighchartR: A Htmlwidget Wrapper Around Highcharts and Highstock APIs

HighchartR

This is an early development version of the highchartR library, which is a htmlwidget wrapper around Highcharts and Highstock javascript graphing libraries (http://www.highcharts.com/demo).

Installation

The package is currently not available at CRAN, so you need devtools package for the installation. You can install the package as follows:

devtools::install_github('jcizel/highchartR')

There are two functions in the package that do most of the work: highcharts, which acts as a wrapper around the Highcharts library (http://api.highcharts.com/highcharts), and highstocks wraps the Highstock library (http://api.highcharts.com/highstock).

Examples

To be expanded..

Highcharts

data = mtcars
x = 'wt'
y = 'mpg'
group = 'cyl'

highcharts(
    data = data,
    x = x,
    y = y,
    group = group,
    type = 'scatter'
)

Highstock

library(data.table)
library(pipeR)
library(rlist)
library(quantmod)
library(dplyr)

symbols <- c("MSFT","C","AAPL")

symbols %>>%
list.map(
    get(getSymbols(.))
) %>>%
list.map(
    . %>>%
    as.data.frame %>>%
    mutate(
        name = .name,
        date = rownames(.)
    ) %>>%
    select(
        name,
        date,
        price = contains("close")
    ) %>>%
    data.table  
) %>>%
rbindlist ->
    data

highstocks(
    data = data,
    x = 'date',
    y = 'price',
    group = 'name'
)

Download Details:

Author: jcizel
Source Code: https://github.com/jcizel/highchartR 

#r #wrapper #apis 

HighchartR: A Htmlwidget Wrapper Around Highcharts and Highstock APIs
Nat  Grady

Nat Grady

1664306040

Phylowidget: An R Htmlwidgets Package Of Phylotree.js

phylowidget

An R htmlwidgets package of phylotree.js by @spond and @stevenweaver

Since this package is not yet on CRAN, to install, use:

devtools::install_github("sdwfrost/phylowidget")

To test:

library(phylowidget)
nwk <- "(((EELA:0.150276,CONGERA:0.213019):0.230956,(EELB:0.263487,CONGERB:0.202633):0.246917):0.094785,((CAVEFISH:0.451027,(GOLDFISH:0.340495,ZEBRAFISH:0.390163):0.220565):0.067778,((((((NSAM:0.008113,NARG:0.014065):0.052991,SPUN:0.061003,(SMIC:0.027806,SDIA:0.015298,SXAN:0.046873):0.046977):0.009822,(NAUR:0.081298,(SSPI:0.023876,STIE:0.013652):0.058179):0.091775):0.073346,(MVIO:0.012271,MBER:0.039798):0.178835):0.147992,((BFNKILLIFISH:0.317455,(ONIL:0.029217,XCAU:0.084388):0.201166):0.055908,THORNYHEAD:0.252481):0.061905):0.157214,LAMPFISH:0.717196,((SCABBARDA:0.189684,SCABBARDB:0.362015):0.282263,((VIPERFISH:0.318217,BLACKDRAGON:0.109912):0.123642,LOOSEJAW:0.397100):0.287152):0.140663):0.206729):0.222485,(COELACANTH:0.558103,((CLAWEDFROG:0.441842,SALAMANDER:0.299607):0.135307,((CHAMELEON:0.771665,((PIGEON:0.150909,CHICKEN:0.172733):0.082163,ZEBRAFINCH:0.099172):0.272338):0.014055,((BOVINE:0.167569,DOLPHIN:0.157450):0.104783,ELEPHANT:0.166557):0.367205):0.050892):0.114731):0.295021)"
phylowidget(nwk)

A standalone version can be found in the inst/standalone folder.

Download Details:

Author: Sdwfrost
Source Code: https://github.com/sdwfrost/phylowidget 
License: MIT license

#r #widget #javascript 

Phylowidget: An R Htmlwidgets Package Of Phylotree.js
Nat  Grady

Nat Grady

1664301960

Chartist: Chartist.js for R, Powered By Htmlwidgets

Chartist.js for R, powered by htmlwidgets

chartist is an R package to draw charts by Chartist.js via htmlwidgets interface.

Installation

devtools::install_github("yutannihilation/chartist")

Example

set.seed(324)
data <- data.frame(
  day = paste0("day", 1:10),
  A   = runif(10, 0, 10),
  B   = runif(10, 0, 10),
  C   = runif(10, 0, 10)
)

# NSE version
chartist(data, day)

demo1

Download Details:

Author: Yutannihilation
Source Code: https://github.com/yutannihilation/chartist 
License: View license

#r #charts #javascript 

Chartist: Chartist.js for R, Powered By Htmlwidgets
Nat  Grady

Nat Grady

1664298060

ImageR: intense-images Htmlwidget for R

intense-images htmlwidget

This is alpha, but if you do everything just right you might get some worthwhile output. Thanks so much to @tholman for the underlying Javascript library intense-images. Check out Tim's other library giflinks for a laugh.

As I was working on imageR, I discovered this poster Redesign of cluster heatmap visualization technique through this tweet. The full-page zoomable is very similar to the effect achieved by imageR, so imageR might be a good preview for your next conference poster.

Simple Example

`# devtools::install_github("timelyportfolio/imageR")

library(imageR)

tf <- tempfile()
png( file = tf, height = 400, width = 600 )
plot(1:50)
dev.off()

intense(base64::img(tf))

Fancy Lattice 3d in Bootstrap

library(shiny)
library(htmltools)
library(lattice)
library(imageR)

tf <- tempfile()
tf2 <- tempfile()
png( file = tf, height = 400, width = 1600 )
  #example from ?lattice::cloud
  cloud(Sepal.Length ~ Petal.Length * Petal.Width | Species, data = iris,
    screen = list(x = -90, y = 70), distance = .4, zoom = .6)
dev.off()

png( file = tf2, height = 1000, width = 1000)
  #### example from http://www.cceb.med.upenn.edu/pages/courses/BSTA670/2012/R_3D_plot_ex.r
  #--------------------------------
  # persp plot of function
  #--------------------------------
  x <- seq(-10, 10, length= 30)
  y <- x
  f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
  z <- outer(x, y, f)
  z[is.na(z)] <- 1
  op <- par(bg = "white")
  persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
dev.off()

html_print(fluidPage(
  tags$h1("Cloud and Wireframe from Lattice")
  ,fluidRow(style = "height:60%; overflow:hidden;"
    ,column(width = 6,  intense(base64::img(tf)))
    ,column(width = 6,  intense(base64::img(tf2)))
  )
))

With a Title and Caption

tf <- tempfile()
png( file = tf, height = 600, width = 1400 )
plot(1:50)
dev.off()

intense(
  tags$img(
    style = "height:25%;"
    ,"data-title" = "sample intense plot"
    ,"data-caption" = "imageR at work"
    ,src = paste0("data:image/png;base64,",base64enc::base64encode(tf))
  )
)

With a Non-img Target

library(htmltools)
library(imageR)
library(ggplot2)

tf <- tempfile()

png( file = tf, height = 1400, width = 1400 )
  ggplot(diamonds, aes(carat, price)) + geom_hex()
dev.off()

intense(
  tags$div(
    tags$h1("does this work? click and see")
    ,"data-image" = paste0("data:image/png;base64,",base64enc::base64encode(tf))
  )
)

Composeable with Other htmlwidgets

library(htmltools)
library(curl)
library(navr)
library(sortableR)
library(imageR)

n1 <- navr(
  selector = "#sortableR-toolbar"
  ,taglist = tagList(
    tags$ul(id = "sort-navr"
      ,style="line-height:120px; text-align:center; vertical-align:middle;"
      ,tags$li(
        style="border: solid 0.1em white;border-radius:100%;line-height:inherit;width:130px;height:130px;"
        , class="fa fa-binoculars fa-4x"
        #  attribution everywhere Creative Commons Flickr
        #  awesome picture by https://www.flickr.com/photos/12859033@N00/2288766662/
        , "data-image" = paste0(
          "data:image/jpg;base64,"
          ,base64enc::base64encode(
            curl("https://farm4.staticflickr.com/3133/2288766662_c40c168b76_o.jpg","rb")
          )
        )
        , "data-title" = "Binoculars, a working collection"
        , "data-caption" = "awesome picture courtesy Flickr Creative Commons
            <a href = 'https://www.flickr.com/photos/12859033@N00/2288766662/'>jlcwalker</a>"
      )        
      ,tags$li(
        style="border: solid 0.1em white;border-radius:100%;line-height:inherit;width:130px;height:130px;"
        , class="fa fa-camera fa-4x"
        #  attribution everywhere Creative Commons Flickr
        #  awesome picture by https://www.flickr.com/photos/s58y/5607717791
        , "data-image" = paste0(
          "data:image/jpg;base64,"
          ,base64enc::base64encode(
            curl("https://farm6.staticflickr.com/5309/5607717791_b030229247_o.jpg","rb")
          )
        )
        , "data-title" = "Leica IIIc converted to IIIf BD ST"
        , "data-caption" = "awesome picture courtesy Flickr Creative Commons
            <a href = 'https://www.flickr.com/photos/s58y/5607717791'>s58y</a>"
      )
    )
  )
)

html_print(tagList(
  tags$div(
    id = "sortableR-toolbar"
    ,style="width:300px;border: dashed 0.2em lightgray; float:left;"
    ,tags$h3("sortableR Icons for Intense Images")
    ,"These icons drag and drop. Click on them for an"
    ,tags$strong("intense")
    ,"result."
  )
  ,add_font_awesome(n1)
  ,sortableR("sort-navr")
  ,intense( selector = "#sort-navr li" )
))

Download Details:

Author: Timelyportfolio
Source Code: https://github.com/timelyportfolio/imageR 
License: MIT license

#r #image 

ImageR: intense-images Htmlwidget for R
Nat  Grady

Nat Grady

1664294109

Exportwidget: R Htmlwidget to Export Other Htmlwidgets and SVG As PNG

exportwidget - htmlwidget to export htmlwidgets

This is pre-alpha and experimental v0.2.0 but should work. Note, this currently does not work in RStudio Viewer. export_widget was the widget of the week at Building Widgets, so you can see it in action in this blog post.

Thanks so much to the following libraries and their authors.

  1. fabric.js
  2. Download-File-JS

Install

devtools::install_github("timelyportfolio/exportwidget")

Example with an htmlwidget | DiagrammeR

library(pipeR)
library(htmltools)
library(DiagrammeR)
library(exportwidget)

tagList(
  grViz(" digraph { a->b; b->c; c->a; }")
  ,export_widget( )
) %>>% html_print( viewer = utils::browseURL ) #export not working in RStudio Viewer

Example with multiple htmlwidgets

library(pipeR)
library(htmltools)
library(DiagrammeR)
library(rcdimple)
library(networkD3)
library(exportwidget)

tagList(
  grViz(" digraph { a->b; b->c; c->a; }")
  ,dimple(
    mtcars
    , mpg ~ cyl
    , groups = "cyl"
    , type = "bubble"
  )
  ,simpleNetwork(
    data.frame(
      Source = c("A", "A", "A", "A", "B", "B", "C", "C", "D")
      ,Target = c("B", "C", "D", "J", "E", "F", "G", "H", "I")
    )
    ,height = 400
    ,width = 400
  )
  ,export_widget( )
) %>>% html_print( viewer = utils::browseURL ) #export not working in RStudio Viewer
library(streamgraph)
library(dplyr)
library(exportwidget)
library(webshot)
library(ggplot2movies)

movies %>%
    select(year, Action, Animation, Comedy, Drama, Documentary, Romance, Short) %>%
    tidyr::gather(genre, value, -year) %>%
    group_by(year, genre) %>%
    tally(wt=value) %>%
    ungroup %>%
    mutate(year=as.Date(sprintf("%d-01-01", year))) -> dat

html_print(tagList(
  streamgraph(dat, "genre", "n", "year")
  ,export_widget( )
)) %>%
  normalizePath(.,winslash="/") %>%
  gsub(x=.,pattern = ":/",replacement="://") %>%
  paste0("file:///",.) %>%
  webshot( file = "stream_screen.png", delay = 10 )

Download Details:

Author: Timelyportfolio
Source Code: https://github.com/timelyportfolio/exportwidget 
License: MIT license

#r #widget #svg #png 

Exportwidget: R Htmlwidget to Export Other Htmlwidgets and SVG As PNG
Nat  Grady

Nat Grady

1664290168

svgPanZoom: R Htmlwidget for svg-pan-zoom.js

svgPanZoom - htmlwidget to Pan / Zoom R graphics

svgPanZoom is a htmlwidgets wrapper for svg-pan-zoom.js. svgPanZoom gives R users an easy way to add panning and zooming to any R graphics (base, ggplot2, lattice, and lots more). It prioritizes ease and simplicity, but does offer some ability to tailor the experience and enhance the interactivity.

Install It

To get started, you may choose from CRAN install.packages("devtools") or Github remotes::install_github("timelyportfolio/svgPanZoom"). svgPanZoom is fairly stable, so CRAN is likely your best choice.

Use It

As stated in the introduction svgPanZoom works with almost all R graphics types. For base graphics, we'll need the svglite package.

library(svgPanZoom) # see install step above
library(svglite)

svgPanZoom(
  svglite:::inlineSVG(
    plot(1:10)
  )
)

Use It in Shiny

There are lots more examples below, but real quickly here is how we can use it in Shiny.

library(shiny)
library(svglite)
library(svgPanZoom)
library(ggplot2)

ui <- shinyUI(bootstrapPage(
  
  svgPanZoomOutput(outputId = "main_plot")
  
))

server = shinyServer(function(input, output) {
  output$main_plot <- renderSvgPanZoom({
    p <- ggplot() + geom_point(data=data.frame(faithful),aes(x=eruptions,y=waiting)) + stat_density2d(data=data.frame(faithful),aes(x=eruptions,y=waiting, alpha =..level..),geom="polygon") + scale_alpha_continuous(range=c(0.05,0.2))
    svgPanZoom(p, controlIconsEnabled = T)
  })
})
  
runApp(list(ui=ui,server=server))

Use It With Grid and More

svglite also works with grid graphics, such as ggplot2 and lattice. Before I show an example though, I highly recommend using gridSVG for ggplot2 and lattice. For some good reasons, please see this from Paul Murrell and Simon Potter. If you are making big graphics--think maps, multiple graphs, etc.--for speed stick with svglite. Here is a simple example using ggplot2 with svglite and svglite:::inlineSVG.

library(svgPanZoom)
library(svglite)
library(ggplot2)

svgPanZoom(
  svglite:::inlineSVG(
    #will put on separate line but also need show
    show(
      ggplot(data.frame(x=1:10,y=1:10),aes(x=x,y=y)) + geom_line()

    )
  )
)

Now let's do that same plot with gridSVG.

svgPanZoom(
  ggplot(data.frame(x=1:10,y=1:10),aes(x=x,y=y)) + geom_line()
)

You might notice right off that sizing is better handled, but more importantly, the resulting SVG is much better structured XML. That small time lag will really start to hurt if you are using gridSVG with large or complicated graphics. So if speed is important, ignore the better structure from gridSVG and stick with svglite.

As promised, lattice (yes, I still use it and like it) works just as nicely.

library(svgPanZoom)
library(svglite)
library(lattice)
 
# with gridSVG
svgPanZoom(
  xyplot( y~x, data.frame(x=1:10,y=1:10), type = "b" )
)

# with svgPlot
svgPanZoom(
  svglite:::inlineSVG(
    show(xyplot( y~x, data.frame(x=1:10,y=1:10), type = "b" ))
  )
)

If you are not impressed yet, then maybe the graphics were not compelling enough. Let's add svgPanZoom to some more complicated visualizations.

library(choroplethr)
# from chorplethr documetation
data(df_pop_state)
m = state_choropleth(
  df_pop_state
  , title="US 2012 State Population Estimates"
  , legend="Population"
)
# take a peek
m
# would be so much more fun with pan and zoom
svgPanZoom( m )
# if your map is big and hairy do this instead
svgPanZoom(
  svglite:::inlineSVG(
    show(m )
    # will have to manually size the svg device
    , height = 10, width = 16 )
)

How about using ggfortify? Here are some great examples. Let's make some pan and zoom.

# devtools::install_github('sinhrks/ggfortify')
library(ggfortify)
svgPanZoom(
  autoplot(lm(Petal.Width ~ Petal.Length, data = iris))
)

library(survival)
svgPanZoom(
  autoplot(survfit(Surv(time, status) ~ sex, data = lung))
)

If ternary diagrams excite you, let's do this USDA soil example from ggtern.

#install.packages("ggtern")

# use example from ?ggtern::USDA
library(ggtern)
library(plyr)
#Load the Data.
data(USDA)
#Put tile labels at the midpoint of each tile.
USDA.LAB <- ddply(USDA,"Label",function(df){apply(df[,1:3],2,mean)})
#Tweak
USDA.LAB$Angle=0; USDA.LAB$Angle[which(USDA.LAB$Label == "Loamy Sand")] = -35

# Construct the plot.
gTern <- ggtern(data=USDA,aes(Sand,Clay,Silt,color=Label,fill=Label)) +
  geom_polygon(alpha=0.75,size=0.5,color="black") +
  geom_mask() +  
  geom_text(data=USDA.LAB,aes(label=Label,angle=Angle),color="black",size=3.5) +
  theme_rgbw() + 
  theme_showsecondary() +
  theme_showarrows() +
  weight_percent() + guides(fill='none') + 
  theme_legend_position("topleft")
  labs(
    title="USDA Textural Classification Chart",
    fill="Textural Class",color="Textural Class"
  )

       
svgPanZoom(gTern)

The true test for me though will be financial time series plots. Will svgPanZoom pass the test?

library(svgPanZoom)
library(svglite)
library(PerformanceAnalytics)

data(edhec)

svgPanZoom(
  svglite:::inlineSVG(
    charts.PerformanceSummary(
      edhec
      ,main = "Performance of EDHEC Indicies"
    )
  ),
  controlIconsEnabled = TRUE
)

library(quantmod)
getSymbols("JPM", from = "2013-12-31")
svgPanZoom(
  svglite:::inlineSVG(
    chartSeries(JPM, theme = chartTheme('white'),
        multi.col=T,TA="addVo();addBBands();addCCI()")
    ,height = 7
    ,width = 12
  )
)

Tal Galili's dendextend offers another great use case for pan and zoom interaction. Let's look at one of the examples from the package vignette.

# install.packages("dendextend")
library(dendextend)
library(svglite)
library(svgPanZoom)

data(iris) 
d_iris <- dist(iris[,-5]) # method="man" # is a bit better
hc_iris <- hclust(d_iris)
dend_iris <- as.dendrogram(hc_iris)
iris_species <- rev(levels(iris[,5]))
dend_iris <- color_branches(dend_iris,k=3, groupLabels=iris_species)
# have the labels match the real classification of the flowers:
labels_colors(dend_iris) <-
   rainbow_hcl(3)[sort_levels_values(
      as.numeric(iris[,5])[order.dendrogram(dend_iris)]
   )]

# We'll add the flower type
labels(dend_iris) <- paste(as.character(iris[,5])[order.dendrogram(dend_iris)],
                           "(",labels(dend_iris),")", 
                           sep = "")

dend_iris <- hang.dendrogram(dend_iris,hang_height=0.1)

# reduce the size of the labels:
dend_iris <- assign_values_to_leaves_nodePar(dend_iris, 0.5, "lab.cex")

par(mar = c(3,3,3,7))
svglite:::inlineSVG(
  {
    plot(dend_iris, 
         main = "Clustered Iris dataset
         (the labels give the true flower species)", 
         horiz =  TRUE,  nodePar = list(cex = .007))
    legend("topleft", legend = iris_species, fill = rainbow_hcl(3))
  }
  , height = 12, width = 14
) %>% svgPanZoom

For what I consider the ultimate test, will it work with HiveR?

# from HiveR documentation ?plotHive 
library(HiveR)
library(grid)
library(svglite)
library(svgPanZoom)

data(HEC)
svgPanZoom(
  svglite:::inlineSVG(
    {
      data(HEC)
      currDir = getwd()
      setwd(system.file("extdata", "Misc", package = "HiveR"))
      plotHive(HEC, ch = 0.1, bkgnd = "white",
               axLabs = c("hair\ncolor", "eye\ncolor"),
               axLab.pos = c(1, 1),
               axLab.gpar = gpar(fontsize = 14),
               anNodes = "HECnodes.txt",
               anNode.gpar = gpar(col = "black"),
               grInfo = "HECgraphics.txt",
               arrow = c("more\ncommon", 0.0, 2, 4, 1, -2))
      
      grid.text("males", x = 0, y = 2.3, default.units = "native")
      grid.text("females", x = 0, y = -2.3, default.units = "native")
      grid.text("Pairing of Eye Color with Hair Color", x = 0, y = 3.75,
                default.units = "native", gp = gpar(fontsize = 18))
      grid.text("A test of plotHive annotation options", x = 0, y = 3.25,
                default.units = "native", gp = gpar(fontsize = 12))
      grid.text("Images from Wikipedia Commons", x = 0, y = -3.5,
                default.units = "native", gp = gpar(fontsize = 9))
      setwd(currDir)
    }
  , height = 20
  , width = 30)
)

Download Details:

Author: Timelyportfolio
Source Code: https://github.com/timelyportfolio/svgPanZoom 
License: View license

#r #svg #zoom 

svgPanZoom: R Htmlwidget for svg-pan-zoom.js