This famous (Fisher’s or Anderson’s) iris data set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are Iris setosa, versicolor, and virginica.iris is a data frame with 150 cases (rows) and 5 variables (columns) named Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, and Species.

iris3 gives the same data arranged as a 3-dimensional array of size 50 by 4 by 3, as represented by S-PLUS. The first dimension gives the case number within the species subsample, the second the measurements with names Sepal L., Sepal W., Petal L., and Petal W., and the third the species.

Loading the packages required

library(ggplot2)
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
data(iris)
head(iris)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa

Setting up the credentials to publish the graphs on plotly

Sys.setenv("plotly_username"="gupta.ruch")
Sys.setenv("plotly_api_key"="kuaxzjdqnl")

Attaching the dataset to the R search path.The dataset will be searched by R when evaluating a variable, so objects objects in the dataset cann be accessed by simoly giving their names.

attach(iris)
g<- ggplot(iris, aes(Sepal.Length,Sepal.Width))
p<- g+geom_point(aes(color = Species))+geom_smooth()+facet_grid(Species~.)+labs(x = "Length of Sepal", y = "Width of sepal")
print(p)

converting into a plotly

ggplotly(p)

Publishing graphs to your online plotly account

plotly_POST(p, "Sepal.Width vs Sepal.Length for different species of flowers")
## No encoding supplied: defaulting to UTF-8.
## Success! Modified your plotly here -> https://plot.ly/~gupta.ruch/4