#load plotly package
rm(list=ls())
library(plotly)
## Loading required package: ggplot2
##
## 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
Using the mtcars dataset we plot can attempt to understand the relationship of various factors to gas mileage (mpg).
We plot weight (wt) vs. mileage (mpg) spatially along the x/y axes. We visualize the number of cylinders (cyl) as colors and the amount of horsepower (hp) as the size of an individual point in the plot.
plot_ly(data = mtcars, x = ~wt, y = ~mpg,
color = ~as.factor(cyl), size = ~hp,
text = ~paste("Weight: ", wt, '<br>MPG:', mpg),
type = "scatter", mode = "markers") %>%
layout(title = "Car Data")
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.