Overview

R Markdown documents are fully reproducible. Use a productive notebook interface to weave together narrative text and code to produce elegantly formatted output. Use multiple languages including R, Python, and SQL. With R Markdown you can format block quotes, footnotes, lists, tables, images, and equations.

Tabs

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse fermentum sit amet tortor a vehicula. Vivamus convallis velit sem, vel hendrerit ipsum fermentum at. Duis nec consequat enim, in efficitur lacus. Etiam facilisis, quam in maximus imperdiet, sem sapien tempor diam, cursus mattis nibh ante sit amet felis. Nullam eu tortor luctus, posuere velit at, malesuada eros. Nunc non hendrerit libero. Sed id quam vitae sem tincidunt vestibulum.

Histograms

Boxplots

Violins


HTML Widgets

htmlwidgets is a package to facilitate the use of JavaScript-based graphics with R. A super nice feature is that the graphics will be rendered in the appropriate way, according to where they are called (in browser, within RStudio’s plot frame, within an R Markdown document, or as part of a Shiny app. Special thanks to Karl Broman’s fantastic tutorial at useR 2016.

DataTables

Sortable, searchable data tables with DT::datatable. DT is an interface to DataTables.

library(DT)
datatable(iris)

scatterD3

Here’s a scatterplot that you can zoom and pan, via scatterD3.

n <- 100
x <- rnorm(n)
y <- rnorm(n)+x
grp <- as.numeric(y < 0)
library(scatterD3)
scatterD3(x, y, lab=paste0("pt", 1:n), col_var=grp,
          colors=c("slateblue", "Orchid"))

Leaflet maps

Here’s a map of California via leaflet

library(ggmap)
addr <- c(`UC Scout` = "3175 Bowers Ave, Santa Clara, CA 95054",
          `CAIR 2016` = "506 S Grand Ave, Los Angeles, CA 90071")
lonlat <- geocode(addr, source="google")
library(leaflet)
leaflet(lonlat) %>%
  addTiles() %>%
  addMarkers(~lon, ~lat, popup = ~as.character(.id))

dygraphs

Zoomable time series plot with dygraphs.

library(dygraphs)
dygraph(sunspots) %>% dyRangeSelector()

d3heatmap

You can make heatmaps with d3heatmap. For example, here’s a heatmap of a correlation matrix:

library(d3heatmap)
d3heatmap(cor(iris[,1:4]), Rowv=FALSE, Colv=FALSE, colors="Blues")

networkD3

For network diagrams, consider networkD3.

library(networkD3)
data(MisLinks)
data(MisNodes)
# Create graph
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
             Target = "target", Value = "value", NodeID = "name",
             Group = "group", opacity = 0.8, zoom = TRUE)

pairsD3

Scatterplot matrices with pairsD3.

library(pairsD3)
pairsD3(iris[,1:4],group=iris[,5],
        labels=gsub("\\.", " ", names(iris)))

three.js

The threejs package provides interactive 3d scatterplots and globe plots using three.js.

library(threejs)
data(world.cities, package="maps")
cities <- world.cities[order(world.cities$pop,decreasing=TRUE)[1:1000],]
value  <- 100 * cities$pop / max(cities$pop)

earth <- texture(system.file("images/world.jpg",package="threejs"))
globejs(img=earth, lat=cities$lat, long=cities$long, value=value)

Plotly for R

Plotly for R is an interactive, browser-based charting library built on the open source javascript graphing library, plotly.js.

library(plotly)
plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length,
        marker = list(size = 10,
                       color = 'rgba(255, 182, 193, .9)',
                       line = list(color = 'rgba(152, 0, 0, .8)',
                                   width = 2))) %>%
  layout(title = 'Styled Scatter',
         yaxis = list(zeroline = FALSE),
         xaxis = list(zeroline = FALSE))