August 17, 2017

Presentation with embedded Plotly Chart

This is a simple presentation that combines a R markdown presentation with a Plotly chart. The chart is interactive with text markers at each data point.

The chart shows…

  • A scatter plot of weight vs. displacement
  • Is colored by cylinder
  • Has a loess curve added to the chart as a trace.

Slide with Plot

Code for the Plot

library(plotly)
data(mtcars)
plot_ly(data = mtcars, 
        x = mtcars$wt, 
        y = mtcars$disp, 
        mode = "markers", 
        type = "scatter", 
        color = as.factor(mtcars$cyl)
        ) %>%
  add_trace(x = mtcars$wt,
            y = ~fitted((loess(mtcars$disp ~ mtcars$wt)))) %>%
  layout(title="Scatter plot + loess curve",
         xaxis = list(title = "weight"),
         yaxis = list(title = "displacement"))