tugas<-read.csv("C:/Users/Saintek9/Downloads/iris.csv",header= TRUE)
head(tugas)
## 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
Mean, Q1, Median, Mean, Q3, Minimal, dan Maximal
summary(tugas)
## 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
Modus
modus <- function(x){
uniqx<- unique(x)
uniqx[which.max(tabulate(match(x, uniqx)))]
}
modus(tugas$SepalLengthCm)
## [1] 5
modus(tugas$SepalWidthCm)
## [1] 3
modus(tugas$PetalLengthCm)
## [1] 1.5
modus(tugas$PetalWidthCm)
## [1] 0.2
modus(tugas$Species)
## [1] "Iris-setosa"
Rata-rata Geometri
mn.geom <- function(x){
exp(mean(log(x)))
}
mn.geom(tugas$SepalLengthCm)
## [1] 5.78572
mn.geom(tugas$SepalWidthCm)
## [1] 3.023582
mn.geom(tugas$PetalLengthCm)
## [1] 3.239757
mn.geom(tugas$PetalWidthCm)
## [1] 0.837827
Rata-rata Harmoni
harmoni<- function(x){
1/(mean(1/x))
}
harmoni(tugas$SepalLengthCm)
## [1] 5.728905
harmoni(tugas$SepalWidthCm)
## [1] 2.993137
harmoni(tugas$PetalLengthCm)
## [1] 2.696472
harmoni(tugas$PetalWidthCm)
## [1] 0.4866465
Skewness dan Kurtosis
library(e1071)
skewness(tugas$SepalLengthCm)
## [1] 0.3086407
skewness(tugas$SepalWidthCm)
## [1] 0.3274013
skewness(tugas$PetalLengthCm)
## [1] -0.2689994
skewness(tugas$PetalWidthCm)
## [1] -0.102906
kurtosis(tugas$SepalLengthCm)
## [1] -0.6058125
kurtosis(tugas$SepalWidthCm)
## [1] 0.1983681
kurtosis(tugas$PetalLengthCm)
## [1] -1.416683
kurtosis(tugas$PetalWidthCm)
## [1] -1.357368
Boxplot
boxplot(tugas$SepalLengthCm, xlab="Sepal Length", ylab="cm", col = "pink")
boxplot(tugas$SepalWidthCm, xlab="Sepal Width", ylab="cm", col = "skyblue")
boxplot(tugas$PetalLengthCm, xlab="Petal Length", ylab="cm", col = "darkseagreen1")
boxplot(tugas$PetalWidthCm, xlab="Petal Width", ylab="cm", col = "darkslategray1")
bp <- cbind(tugas$SepalLengthCm , tugas$SepalWidthCm , tugas$PetalLengthCm , tugas$PetalWidthCm)
boxplot(bp, xlab="grup", ylab="cm",col=c("pink","skyblue","darkseagreen1","darkslategray1"))
Histogram
par(mfrow = c(2, 2))
hist(tugas$SepalLengthCm, main = "Sepal Length",xlab = "Sepal Legth (cm) ", col = "lavenderblush" )
hist(tugas$SepalWidthCm, main = "Sepal Width",xlab = "Sepal Width (cm)", col = "lightcyan")
hist(tugas$PetalLengthCm, main = "Petal Length",xlab = "Petal Length (cm)", col = "lightpink")
hist(tugas$PetalWidthCm, main = "Petal Width",xlab = "Petal Width (cm)", col = "lightsalmon")
Scatter PLot
par(mfrow = c(2, 2))
plot(tugas$SepalLengthCm,tugas$SepalWidthCm, pch = 19, cex = 0.8, frame = FALSE, xlab = "Sepal Length", ylab = "Sepal Width", main ="Korelasi", col="blue")
plot(tugas$SepalLengthCm,tugas$PetalLengthCm, pch = 19, cex = 0.8, frame = FALSE, xlab = "Sepal Length", ylab = "Petal Length", main ="Korelasi", col="lightsalmon")
plot(tugas$SepalLengthCm,tugas$PetalWidthCm, pch = 19, cex = 0.8, frame = FALSE, xlab = "Sepal Length", ylab = "Petal Width", main ="Korelasi", col="palegreen")
plot(tugas$SepalWidthCm,tugas$PetalLengthCm, pch = 19, cex = 0.8, frame = FALSE, xlab = "Sepal Width", ylab = "Petal Length", main ="Korelasi", col="mistyrose" )
par(mfrow = c(2, 2))
plot(tugas$SepalWidthCm,tugas$PetalWidthCm, pch = 19, cex = 0.8, frame = FALSE, xlab = "Sepal Width", ylab = "Petal Width", main ="Korelasi", col="lightsalmon" )
plot(tugas$PetalLengthCm,tugas$PetalWidthCm, pch = 19, cex = 0.8, frame = FALSE, xlab = "Petal Length", ylab = "Petal Width", main ="Korelasi", col="palegreen" )
Diagram Batang
barplot(tugas$SepalLengthCm, names.arg = "Sepal Length", col="lavenderblush")
barplot(tugas$SepalWidthCm, names.arg = "Sepal Length", col="skyblue")
barplot(tugas$PetalLengthCm, names.arg = "Sepal Length", col="lightsalmon")
barplot(tugas$PetalLengthCm, names.arg = "Sepal Length", col="lightgreen")
Pie Chart
library(plotrix)
dl <- c("Iris Sentosa", "Iris Versi Color", "Iris Virginica")
pie(table(tugas$Species), col = c("darkseagreen1", "darkseagreen3", "darkolivegreen1"))
pie3D(table(tugas$Species),labels = dl, explode = 0.1, main = "Pie Chart of Species", col = c("darkseagreen1", "darkseagreen3", "darkolivegreen1"))
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.