This is a simple demo of how an interactive plot can be added into R markdown document using Plotly library. In this case we will add an interactive surface plot for the ‘volcano’ dataset (included in R) and a scatter plot using ‘mtcars’ dataset.

# Loading Plotly library
library(plotly)
# Creating interactive surface plot
plot_ly(z=volcano, type="surface")
# Creating interactive scatter plot
plot_ly(data = mtcars, x = ~wt, y = ~mpg, 
        color = ~as.factor(cyl), size = ~hp,
        text = ~paste("Weight: ", wt, 'MPG:', mpg),
        type = "scatter",
        mode = "markers",
        fill = ~'')