loading the libraries we will be working with

We will use plotly and we might need dplyr for data manipulation:

if (!require("plotly")) install.packages("plotly")
## Loading required package: 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

suppressMessages() cuts off some output printouts that clutter the document

suppressMessages(library(plotly))
suppressMessages(library(dplyr))

Trying plotly on Iris data

We can try two types of plot from the package description examples, box and scatter

plot_ly(iris, x = ~Petal.Width, color = ~Species, type = "box")

scatter plots

plot_ly(
  data = iris,
  x = ~Petal.Length,
  y = ~Petal.Width,
  type = "scatter",
  mode = "markers",
  color = ~Species
)
data("storms")
storms %>% head()
## # A tibble: 6 x 13
##   name   year month   day  hour   lat  long status       category  wind pressure
##   <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <chr>        <ord>    <int>    <int>
## 1 Amy    1975     6    27     0  27.5 -79   tropical de… -1          25     1013
## 2 Amy    1975     6    27     6  28.5 -79   tropical de… -1          25     1013
## 3 Amy    1975     6    27    12  29.5 -79   tropical de… -1          25     1013
## 4 Amy    1975     6    27    18  30.5 -79   tropical de… -1          25     1013
## 5 Amy    1975     6    28     0  31.5 -78.8 tropical de… -1          25     1012
## 6 Amy    1975     6    28     6  32.4 -78.7 tropical de… -1          25     1012
## # … with 2 more variables: ts_diameter <dbl>, hu_diameter <dbl>

trying out storms data

plot_ly(data = storms, x = ~category, y =~wind, color = ~status, type = "scatter", mode = "markers", size = 5, alpha = .4)