February 21, 2017

Plotly Assignment

For this assignment, we will create an interactive plot with the following steps

  1. Load plotly package and mtcars dataset
  2. Create a 3D scatter plot

Code to load package and data

suppressPackageStartupMessages({library(plotly)})
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("#132B43", "#56B1F7")) %>%
             add_markers() %>% 
             layout(title = 'Simple 3D Scatter Plot',
                    scene = list(xaxis = list(title = 'Weight (1000lbs)'),
                                 yaxis = list(title = 'Gross horsepower'),
                                 zaxis = list(title = '1/4 mile time')))

Create 3D Scatter Plot