Introduction :

Creating a web page using R Markdown that features a plot created with Plotly package in R.

This creates 3D plots with code attached, where i trying to show the real benefit of using “Plotly” package.

R Studio Knit HTML with install.packages line

if (!require('ggplot2')) 
{
  install.packages('ggplot2');
  library(ggplot2);
}
## Loading required package: ggplot2

To install Plotly package

#install.packages("plotly")
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout

Mtcars 3D plot

data("mtcars") ##loading required data


mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)

p <- plot_ly(mtcars, x = ~wt, y = ~hp,
             z = ~qsec, color = ~am,
             colors = c('#BF382A',
                        '#0C4B8E')) %>%
    add_markers() %>% 
    layout(scene = list(
        xaxis = list(title = 'Weight'),
        yaxis = list(title = 'Gross horsepower'),
        zaxis = list(title = '1/4 mile time'))); p