How to Add an Interactive R Visualization to a Blog in Under 30 Seconds
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. This particular example doesn't mean anything, 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 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 firstname.lastname@example.org, and we typically add it in a few days.
Step 4: Export > Embed > 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)
This example is from the networkD3 package, by Christopher Gandrud, JJ Allaire, & Kent Russell: http://christophergandrud.github.io/networkD3/