iris <- read.csv("iris.data", header=FALSE)
colnames(iris) <- c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species")
head(iris)
The iris dataset (obtained from the UCI Machine Learning Repository: https://archive.ics.uci.edu/ml/datasets/iris) contains a total of 150 observations and 5 variables:
iris$Species <- as.factor(iris$Species)
summary(iris)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.054 Mean :3.759 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
## Species
## Iris-setosa :50
## Iris-versicolor:50
## Iris-virginica :50
##
##
##
The mean sepal length across all 150 iris flowers is 5.8433333.
par(mfrow=c(2,2))
hist(iris$Sepal.Length, main="Sepal Length", xlab="Length (cm)")
hist(iris$Sepal.Width, main="Sepal Width", xlab="Width (cm)")
hist(iris$Petal.Length, main="Petal Length", xlab="Length (cm)")
hist(iris$Petal.Width, main="Petal Width", xlab="Width (cm)")
Sepal length and width are fairly normally distributed, while petal length and width are right-skewed.
pairs(iris[1:4], main="Iris Data", pch=21, bg=c("red","green3","blue")[unclass(iris$Species)])
By taking a look at the scatter plots the positive correlations between all the measurement variables become apparent. Moreover, it can be observed that the species are separated well, especially by petal dimensions.
boxplot(Sepal.Length ~ Species, data=iris, main="Sepal Length by Species",
xlab="Iris Species", ylab="Sepal Length (cm)", col=c("red","green3","blue"))
As can be seen in the boxplot above, setosa has the smallest sepals, while virginica has the largest ones and versicolor is in between the two.
In a nutshell, this exploratory analysis of the iris dataset highlights the differences between species in their sepal and petal sizes, with setosa having the smallest floral dimensions and virginica the largest. Moreover, the variables are correlated with each other but the species can still be distinguished by petal measurements.