21 February 2017 | by Tim Bock

How to Add an Interactive R Visualization to a Blog in Under 30 Seconds

Interactive visualization in R

Check out the interactive R visualization below. Click on one of the circles with lots of lines connected to it and drag it around. I find this quite enjoyable. Does it mean anything? I do not think so, but the purpose of my post here is just to show the technology. The total time to set this visualization up and include it on this blog was about 30 seconds.

 

 


 

Seven steps to include your interactive R visualization in a blog

Step 1: Open this example in Displayr.

Step 2: In Displayr, click Insert > Analysis > R Output.

Step 3: Paste your R Code into Displayr or the code I used is below. If you do not have this prepared, it will take a lot longer than 30 seconds. 😉 A good place to start if looking for examples is www.htmlwidgets.org. If you want to use a package that is not in Displayr, just send us an email on support@displayr.com, and we typically add it in a few days.

Step 4: Export > Embed > Snapshot and View.

Step 5: Copy the HTML snippet (i.e., <script src=…).

Step 6: Insert the HTML snippet into your page. For example, to do this in WordPress, just click on the Text tab and paste the code in.

Step 7: Publish your blog!

 


 

The code for the example

library(networkD3)
data(MisLinks, MisNodes)
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.4)

 


Acknowledgements

This example is from the networkD3 package, by Christopher Gandrud, JJ Allaire, & Kent Russell: http://christophergandrud.github.io/networkD3/

Author: Tim Bock

Tim Bock is the founder of Displayr. Tim is a data scientist, who has consulted, published academic papers, and won awards, for problems/techniques as diverse as neural networks, mixture models, data fusion, market segmentation, IPO pricing, small sample research, and data visualization. He has conducted data science projects for numerous companies, including Pfizer, Coca Cola, ACNielsen, KFC, Weight Watchers, Unilever, and Nestle. He is also the founder of Q www.qresearchsoftware.com, a data science product designed for survey research, which is used by all the world’s seven largest market research consultancies. He studied econometrics, maths, and marketing, and has a University Medal and PhD from the University of New South Wales (Australia’s leading research university), where he was an adjunct member of staff for 15 years.

Categories

Explore Displayr

Follow the seven steps in this blog to include your interactive R visualization in a blog.

TRY IT OUT



No comment. Share your thoughts.

Leave a Reply

Your email address will not be published. Required fields are marked *

Human? *

Keep updated with the latest in data science.