Plotting Iris flower dataset using Plotly

Shubham Agrawal

3 December 2018

Introduction

The Iris flower data set or Fisher’s Iris data set is a multivariate data set introduced by the British statistician and biologist Ronald Fisher in his 1936 paper The use of multiple measurements in taxonomic problems as an example of linear discriminant analysis. It is sometimes called Anderson’s Iris data set because Edgar Anderson collected the data to quantify the morphologic variation of Iris flowers of three related species. Source: Wikipedia

Loading the dataset

The data set consists of 50 samples from each of three species of Iris (Iris setosa, Iris virginica and Iris versicolor). Four features were measured from each sample: the length and the width of the sepals and petals, in centimeters.

data <- datasets::iris
str(data)
## 'data.frame':    150 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
library(plotly)

Plotting a histogram with Petal.Length

p <- plot_ly(data = iris, x = ~Petal.Length, type = 'histogram',
             width = 500, height = 400)
layout(p, title = "Iris Dataset - Petal.Length",
       yaxis = list(title = "Count"))

Plotting a Boxplot with Petal.Width

p <- plot_ly(data = iris, y = ~Petal.Width, type = 'box',
             width = 650, height = 450, color = ~Species)
layout(p, title = "Iris Dataset - Petal.Width")

Plotting a Violin plot with Sepal.Length

p <- plot_ly(data = iris, y = ~Sepal.Length, type = 'violin',
             width = 650, height = 450, color = ~Species)
layout(p, title = "Iris Dataset - Sepal.Length")

Plotting a Scatter Plot

p <- plot_ly(data = iris, x = ~Sepal.Length,y = ~Petal.Length, 
            type = 'scatter', mode = 'markers', color = ~Species,
            size = ~Petal.Width, width = 650, height = 400)
layout(p, title = "Iris Dataset - Sepal.Length vs Petal.Width")