For this assignment, we will create an interactive plot with the following steps
- Load plotly package and mtcars dataset
- Create a 3D scatter plot
February 21, 2017
For this assignment, we will create an interactive plot with the following steps
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')))