x = read.csv("C:/Users/User/Downloads/iris.csv",header=TRUE)
head(x)
## Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species
## 1 1 5.1 3.5 1.4 0.2 Iris-setosa
## 2 2 4.9 3.0 1.4 0.2 Iris-setosa
## 3 3 4.7 3.2 1.3 0.2 Iris-setosa
## 4 4 4.6 3.1 1.5 0.2 Iris-setosa
## 5 5 5.0 3.6 1.4 0.2 Iris-setosa
## 6 6 5.4 3.9 1.7 0.4 Iris-setosa
str(x)
## 'data.frame': 150 obs. of 6 variables:
## $ Id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ SepalLengthCm: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
## $ SepalWidthCm : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
## $ PetalLengthCm: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
## $ PetalWidthCm : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
## $ Species : chr "Iris-setosa" "Iris-setosa" "Iris-setosa" "Iris-setosa" ...
head(x)
## Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species
## 1 1 5.1 3.5 1.4 0.2 Iris-setosa
## 2 2 4.9 3.0 1.4 0.2 Iris-setosa
## 3 3 4.7 3.2 1.3 0.2 Iris-setosa
## 4 4 4.6 3.1 1.5 0.2 Iris-setosa
## 5 5 5.0 3.6 1.4 0.2 Iris-setosa
## 6 6 5.4 3.9 1.7 0.4 Iris-setosa
x.num= x[,1:4]
summary(x)
## Id SepalLengthCm SepalWidthCm PetalLengthCm
## Min. : 1.00 Min. :4.300 Min. :2.000 Min. :1.000
## 1st Qu.: 38.25 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600
## Median : 75.50 Median :5.800 Median :3.000 Median :4.350
## Mean : 75.50 Mean :5.843 Mean :3.054 Mean :3.759
## 3rd Qu.:112.75 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100
## Max. :150.00 Max. :7.900 Max. :4.400 Max. :6.900
## PetalWidthCm Species
## Min. :0.100 Length:150
## 1st Qu.:0.300 Class :character
## Median :1.300 Mode :character
## Mean :1.199
## 3rd Qu.:1.800
## Max. :2.500
var(x.num)
## Id SepalLengthCm SepalWidthCm PetalLengthCm
## Id 1887.500000 25.78288591 -7.49228188 67.6677852
## SepalLengthCm 25.782886 0.68569351 -0.03926846 1.2736823
## SepalWidthCm -7.492282 -0.03926846 0.18800403 -0.3217128
## PetalLengthCm 67.667785 1.27368233 -0.32171275 3.1131794
#membuat pie chart untuk spesies
pie(table(x$Species))

#mengatur pelatakan grafik
par(mfrow=c(2,2),oma=c(1,1,1,1))
#membuat histogram tiap atribut
hist(x$SepalLengthCm,col="light pink")
hist(x$SepalWidthCm,col="light yellow")
hist(x$PetalLengthCm,col="light blue")
hist(x$PetalWidthCm,col= "thistle2")

#atur peletakan grafik
par(mfrow=c(2,2),mar=c(2,2,2,2))
#membuat boxplot tiap atribut terhadap spesies
boxplot(SepalLengthCm ~ Species, main = "Box Plot Sepal Length - Species", data = x, xlab = "Species", ylab = "Sepal.Length")
boxplot(SepalWidthCm ~ Species, main = "Box Plot Sepal Width - Species", data = x, xlab = "Species", ylab = "Sepal.Width")
boxplot(PetalLengthCm ~ Species, main = "Box Plot Petal Length - Species", data = x, xlab = "Species", ylab = "Petal.Length")
boxplot(PetalLengthCm ~ Species, main = "Box Plot Petal Width - Species", data = x, xlab = "Species", ylab = "Petal.Width")

#membuat pairs plot tiap atribut terhadap spesies
x.jitter <- apply(x.num,2,function(o){jitter(o)})
x.jitter <- apply(x.num,2,function(o){jitter(o)})
pairs(x.jitter,main="Pairs Plot of x Data",pch=21,bg = c("red", "green", "blue")[unclass(iris$Species)])
