1
GRAFIK MENGGUNAKAN R- CLI
Matakuliah : KOMPUTASI STATISTIKA Tahun : Tahun 2020
Program Studi Statistika
Fakultas Matematika dan Ilmu Pengetahuan Alam Surakarta, 2020
Outline
Buka dan tutup jendela grafik
Fungsi plot utama
Fungsi plot tambahan
Fungsi plot interaktif
Notasi matematika pd plot
Setting grafik
1.Buka dan tutup jendela grafik
Aktifkan dg perintah
>win.graph() atau windows()
Tutup dg perintah
>graphics.off() atau dev.off()
R memiliki bbrp library ttg grafik
Kita gunakan graphics
Cek library dengan
>search()
3
Lanjutan ...
Terlihat library graphics ada di nomor ..
Cek perintah2 yg ada di library graphics
>objects(nomor urut)
2. Fungsi plot utama
Diagram pencar
>plot (X,Y)
5
M 1 2 3 4 5 6 7 8 9 10
X (har ga)
1.3 2 1.7 1.5 1.6 1.2 1.6 1.4 1 1.1
Y (sale s)
10 12 5 12 10 15 5 12 17 20
Lanjutan
Plot menurut indeks
>plot(sales)
>win.graph() #buka jendela baru
>y=ts(sales)
>plot(y)
Lanjutan
Plot data bertipe faktor
Gunakan data HBAT.SAV (data dari buku Hair dkk (2006): Multivariate data analysis
Data berisi profil responden, tingkat persepsi terhadap variabel2
pemasaran(kualitas produk, image website, kecepatan pengiriman, dll serta tingkat kepuasan konsumen)
7
Lanjutan ...
Panggil data dg R-Commander
>Data>Impor data>dari dataset SPSS atau
>load(dimana data tersimpan)
>summary(hbat$x1)
>plot(hbat$x1)
Mis dibuat boxplot var metrik
berdasarkan var non metrik (faktor)
>plot(hbat$x19~hbat$x1)
Perintah qqnorm(x), qqline(x),qqplot(x,y)
Q-Q plot adl perintah utk membuat dan menampilkan plot quantile2
qqnorm utk uji apakah data berdistribusi normal
qqplot utk membuat perbandingan dg distribusi lain
qqline utk menambahkan grs dari
kuantil pertama ke kuantil ke tiga dlm plot qqnorm
9
Uji kecocokan terhadap distribusi normal
>qqnorm(hbat$x6) #perintah membuat kuantil2
>qqline(hbat$x6) # kuantil teoritis
>qqline(hbat$x6, col=2) #memberi warna
Uji kecocokan terhadap
distribusi statistik tertentu
Mis dipunyai
>y=rt(100,df=4)
>qqnorm(y)
>qqline(y, col=2)
Data y tidak berdistribusi normal
Apa distribusi data y
>Qteori=rt(200,df4) #distribusi teoritis sbg pembanding
>qqplot(Qteori,y)
Distribusi t dg df=4 re,atif cukup baik utk memodelkan data y
11
hist()
Perintah utk membuat histogram
>hist(hbat$x19)
>hist(hbat$x19,breaks=20)
>hist(hbat$x19,breaks=20,col=“green”, border=“pink”)
Image, contour, persp
persp plot 3 dimensi
image dan contour utk plot proyeksi 2 dimensi
Contoh
>y=seq(-20,20,0.5)
>x=seq(-20,20,0.5)
>z=outer(x^2,y^2,”*”)
>persp(x,y,z)
>persp(x,y,z,theta=30,phi=30,col=“gree
n” 13
>image (x,y,z)
Contour(x,y,z)
3. Fungsi plot tambahan
points(x,y)
lines(x,y)
text(x,y,labels,...)
dsb
15
4. Fungsi plot interaktif
locator(n,type)
locator()
identify(x,y,labels)
5. Notasi matematika pada plot
>help(plotmath)
>example(plotmath)
>demo(plotmath)
17
x <- seq(-4, 4, len = 101)
y <- cbind(sin(x), cos(x))
matplot(x, y, type = "l", xaxt = "n", main = expression(paste(plain(sin) * phi, " and ", plain(cos) * phi)), ylab = expression("sin" * phi, "cos" * phi), # only 1st is taken xlab =
expression(paste("Phase Angle ", phi)), col.main = "blue")
axis(1, at = c(-pi, -pi/2, 0, pi/2, pi), labels = expression(-pi, -pi/2, 0, pi/2,
18
6. Setting parameter grafik
Satu jendela lebih dr 1 grafik
par=partisi, mfrow=multi figure row
Contoh
>win.graph()
>par(mfrow=c(2,3))
>hist(hbat$x19)
>plot(hbat$x6,hbat$x19)
>qqnorm(hbat$x19)
>qqplot(hbat$x6)
>plot(hbat$x1~hbat$x19)
>plot(hbat$x19,type=“l”)
19