graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs...
Transcript of graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs...
![Page 1: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/1.jpg)
graphics dalam R
![Page 2: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/2.jpg)
Graphics dalam R
• Graphs dibangun di R dengan dua prinsip1) Membangun Grafik Dasar2) Menambah infomasi pada grafik Dasar
![Page 3: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/3.jpg)
fungsi Graphics
• fungsi dengan level tinggi– Membuat grafik dari data
• Fungsi dengan level rendah– Modifikasi grafik yang telah dibuat
• Parameter grafik– Mengkontrol tampilan grafik
• fungsi dengan level tinggi– Membuat grafik dari data
• Fungsi dengan level rendah– Modifikasi grafik yang telah dibuat
• Parameter grafik– Mengkontrol tampilan grafik
![Page 4: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/4.jpg)
Fungsi Grafik Tingkat Tinggi
• plot()• hist()• barplot()• boxplot()
• plot()• hist()• barplot()• boxplot()
![Page 5: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/5.jpg)
Fungsi Grafik tingkat Rendah
• points()• lines()• abline()• text()• mtext()• title()• legend()etc
• points()• lines()• abline()• text()• mtext()• title()• legend()etc
![Page 6: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/6.jpg)
Graphical parameters
• Parameter diset dengan perintah par()• Mengkontrol bagaimana tampilan grafik
![Page 7: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/7.jpg)
Graphical Type
• Histogram• Box Plot• Bar Plot• Line Plot
• Histogram• Box Plot• Bar Plot• Line Plot
![Page 8: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/8.jpg)
histogram
• Datax1=c(1,2,3,4,4,6,7,10,9)
• Plot histogram:hist(x1)
![Page 9: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/9.jpg)
histogram
• Plot as probabilityhist(x1,prob=T)
![Page 10: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/10.jpg)
histogram
• Plot as probabilityhist(x1,prob=T)
• Add density curvelines(density(x1),col=“red”)
![Page 11: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/11.jpg)
histogram
• Plot as probabilityhist(x1,prob=T)
• Add density curvelines(density(x1),col=“red”)
• Add “rug plot” to locatedatarug(x1,col="blue")
• Plot as probabilityhist(x1,prob=T)
• Add density curvelines(density(x1),col=“red”)
• Add “rug plot” to locatedatarug(x1,col="blue")
![Page 12: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/12.jpg)
boxplot
• boxplot functionboxplot(x1)
![Page 13: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/13.jpg)
boxplot
• boxplot functionboxplot(x1)
• Add titletitle(main="Boxplot ofx1")
• boxplot functionboxplot(x1)
• Add titletitle(main="Boxplot ofx1")
![Page 14: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/14.jpg)
boxplot
• boxplot functionboxplot(x1)
• Add titletitle(main="Boxplot ofx1")
• Plot horizontallyboxplot(x1,main="Boxplotof x1",horizontal=T)
• boxplot functionboxplot(x1)
• Add titletitle(main="Boxplot ofx1")
• Plot horizontallyboxplot(x1,main="Boxplotof x1",horizontal=T)
![Page 15: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/15.jpg)
Boxplot >1
• Datax1=c(1,2,3,4,4,6,7,10,9)x2=c(2,2,2,3,4,2,3,4,1)x3=c(2,3,7,4,8,6,9,11,2)
![Page 16: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/16.jpg)
boxplotboxplot(x1,x2,x3)title(main=“three
boxplots”)
![Page 17: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/17.jpg)
boxplotboxplot(x1,x2,x3)title(main=“three
boxplots”)
ORbp3<-data.frame(x1,x2,x3)boxplot(bp3)
boxplot(x1,x2,x3)title(main=“three
boxplots”)
ORbp3<-data.frame(x1,x2,x3)boxplot(bp3)
![Page 18: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/18.jpg)
boxplotboxplot(x1,x2,x3)title(main=“three
boxplots”)
ORbp3<-data.frame(x1,x2,x3)boxplot(bp3)
boxplot(x1,x2,x3)title(main=“three
boxplots”)
ORbp3<-data.frame(x1,x2,x3)boxplot(bp3)
![Page 19: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/19.jpg)
barplot
barplot(x1)
![Page 20: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/20.jpg)
barplot
barplot(x1,col=rainbow(20))
![Page 21: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/21.jpg)
barplot
barplot(x1)
barplot(x1,col=rainbow(20))
barplot(x1,col=rainbow(20),horizontal=T)
barplot(x1)
barplot(x1,col=rainbow(20))
barplot(x1,col=rainbow(20),horizontal=T)
![Page 22: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/22.jpg)
Barplots data dalam group
Usia A B C D50-54 11.7 8.7 15.4 8.455-59 18.1 11.7 24.3 13.660-64 26.9 20.3 37.0 19.365-69 41.0 30.9 54.6 35.170-74 66.0 54.3 71.1 50.0
Usia A B C D50-54 11.7 8.7 15.4 8.455-59 18.1 11.7 24.3 13.660-64 26.9 20.3 37.0 19.365-69 41.0 30.9 54.6 35.170-74 66.0 54.3 71.1 50.0
![Page 23: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/23.jpg)
BarplotA=c(11.7,18.1,26.9,41,66)B=c(8.7,11.7,20.3,30.9,54.3)C=c(15.4,24.3,37,54.6,71.1)D=c(8.4,13.6,19.3,35.1,50)mydata=data.frame(A,B,C,D)rownames(mydata)=c("50-54","55-59","60-64","65-69","70-74")
mydata2=as.matrix(mydata)
A=c(11.7,18.1,26.9,41,66)B=c(8.7,11.7,20.3,30.9,54.3)C=c(15.4,24.3,37,54.6,71.1)D=c(8.4,13.6,19.3,35.1,50)mydata=data.frame(A,B,C,D)rownames(mydata)=c("50-54","55-59","60-64","65-69","70-74")
mydata2=as.matrix(mydata)
![Page 24: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/24.jpg)
Barplots for grouped databarplot(mydata2)
![Page 25: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/25.jpg)
Barplots for grouped databarplot(mydata2)
barplot(mydata2,col=rainbow(5),legend=T)
![Page 26: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/26.jpg)
Barplots for grouped databarplot(mydata2)
barplot(mydata2,col=rainbow(5),legend=T)
barplot(mydata,col=rainbow(5),legend=T,beside=T)
barplot(mydata2)
barplot(mydata2,col=rainbow(5),legend=T)
barplot(mydata,col=rainbow(5),legend=T,beside=T)
![Page 27: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/27.jpg)
scatterplot
x1=c(1,2,3,4,4,6,7,10,9)
plot(x1)
x1=c(1,2,3,4,4,6,7,10,9)
plot(x1)
![Page 28: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/28.jpg)
scatterplot
• plot(x1,type="l")
![Page 29: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/29.jpg)
scatterplot
par(mfrow=c(3,2))
plot(x1,type="p",main="type p:points")
plot(x1,type="l",main="type l:lines")
plot(x1,type="b",main="type b:both")
plot(x1,type="o",main="type o:overplot")
plot(x1,type="h",main="type h:histogram")
plot(x1,type="s",main="type s:steps")
par(mfrow=c(3,2))
plot(x1,type="p",main="type p:points")
plot(x1,type="l",main="type l:lines")
plot(x1,type="b",main="type b:both")
plot(x1,type="o",main="type o:overplot")
plot(x1,type="h",main="type h:histogram")
plot(x1,type="s",main="type s:steps")
![Page 30: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/30.jpg)
Plotting symbols, par(pch)
• Default : 25 plotting characters dikontrol olehpch parameter Exp :pch = n
• Parameter pch dapat berupa character, ex pch= “x” dan dapat juga berupa vector
• Default : 25 plotting characters dikontrol olehpch parameter Exp :pch = n
• Parameter pch dapat berupa character, ex pch= “x” dan dapat juga berupa vector
![Page 31: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/31.jpg)
Plotting symbols, par(pch)x<-rep(1:5,times=5)y<-rep(1:5,each=5)
par(xpd=T)plot(x,y,type="p",pch=1:25
,cex=3,axes=F,ann=F,bty="n",bg="red")
title(main="Data symbols1:25")
text(x,y,labels=1:25,pos=1,offset=1)
x and y are both vectors of length 25
xpd controls “clipping” of graphics,allows data to be plotted outside themain plot area.
pch is a vector 1:25, so each point has aunique symbol
cex controls the symbol sizebg is background colour
axes = F and ann = F stops the drawing ofaxes and labels
text adds labels to the points, x and ygive locations, labels contains thetext, pos=1 puts the text below thepoints
x<-rep(1:5,times=5)y<-rep(1:5,each=5)
par(xpd=T)plot(x,y,type="p",pch=1:25
,cex=3,axes=F,ann=F,bty="n",bg="red")
title(main="Data symbols1:25")
text(x,y,labels=1:25,pos=1,offset=1)
x and y are both vectors of length 25
xpd controls “clipping” of graphics,allows data to be plotted outside themain plot area.
pch is a vector 1:25, so each point has aunique symbol
cex controls the symbol sizebg is background colour
axes = F and ann = F stops the drawing ofaxes and labels
text adds labels to the points, x and ygive locations, labels contains thetext, pos=1 puts the text below thepoints
![Page 32: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/32.jpg)
Plotting symbols, par(pch)tb=c(160, 165, 175, 180, 185)bb=c(55,60,70,75,80)
![Page 33: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/33.jpg)
Plotting symbols: size and width
• symbol size controlled by cex– cex=n plots a figure n times the default size
• Line width controlled by lwd– lwd=n gives the width of the line
• symbol size controlled by cex– cex=n plots a figure n times the default size
• Line width controlled by lwd– lwd=n gives the width of the line
![Page 34: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/34.jpg)
Plotting symbols: size and width
x<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size and width",xlab="Width (lwd)",ylab="Size (cex)")
x and y generated as in previousexample
Also act as vectors of width: lwd=xand size:
cex=y
pch=3 only uses a single symbol
x<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size and width",xlab="Width (lwd)",ylab="Size (cex)")
x and y generated as in previousexample
Also act as vectors of width: lwd=xand size:
cex=y
pch=3 only uses a single symbol
![Page 35: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/35.jpg)
Plotting symbols: colour
• Colour of objects controlled by “col”• col can be argument to high or low level
functions: outcome determined by context• Colours specified a number of ways:
– by name: see colours() for all names colours– by integer: referring to locations in the current
palette: see palette()– as a location in rgb or other colour space as
• Colour of objects controlled by “col”• col can be argument to high or low level
functions: outcome determined by context• Colours specified a number of ways:
– by name: see colours() for all names colours– by integer: referring to locations in the current
palette: see palette()– as a location in rgb or other colour space as
![Page 36: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/36.jpg)
Plotting symbols: colour
• default palette:> palette()[1] "black" "red" "green3" "blue" "cyan"
"magenta" "yellow" "gray"
• integer values for colours refer to locations inthe palette, recycled as necessary
• default palette:> palette()[1] "black" "red" "green3" "blue" "cyan"
"magenta" "yellow" "gray"
• integer values for colours refer to locations inthe palette, recycled as necessary
![Page 37: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/37.jpg)
Plotting symbols: colourfunction (){x<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,col=1:25,xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size andwidth",xlab="Width (lwd)",ylab="Size (cex)")
}
Identical to previous example, but with acolour argument added to the plotfunction
col here is a vector 1:25, only 8 colours inthe default palette, so they will berecycled
function (){x<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,col=1:25,xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size andwidth",xlab="Width (lwd)",ylab="Size (cex)")
}R users group An introduction to graphics in R
![Page 38: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/38.jpg)
Plotting symbols: colourx<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,col=1:25,xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size andwidth",xlab="Width (lwd)",ylab="Size (cex)")
x<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,col=1:25,xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size andwidth",xlab="Width (lwd)",ylab="Size (cex)")
![Page 39: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/39.jpg)
Plotting symbols: colour• Built-in colour packages:
– rainbow() Vary from red to violet– heat.colors() whiteorangered– terrain.colors() whitebrowngreen– topo.colors() whitebrowngreenblue– grey() shades of grey
• Built-in colour packages:– rainbow() Vary from red to violet– heat.colors() whiteorangered– terrain.colors() whitebrowngreen– topo.colors() whitebrowngreenblue– grey() shades of grey
![Page 40: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/40.jpg)
Plotting symbols: colour
x<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,col=rainbow(25),xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size and width",xlab="Width (lwd)",ylab="Size (cex)")
x<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,col=rainbow(25),xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size and width",xlab="Width (lwd)",ylab="Size (cex)")
![Page 41: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/41.jpg)
Plotting symbols: colourx<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,col=heat.colors(25),xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size and width",xlab="Width (lwd)",ylab="Size (cex)")
x<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,col=heat.colors(25),xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size and width",xlab="Width (lwd)",ylab="Size (cex)")
![Page 42: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/42.jpg)
Plotting symbols: colourx<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,col=grey(1:25)/25,xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size and width",xlab="Width (lwd)",ylab="Size (cex)")
x<-rep(1:5,times=5)y<-rep(1:5,each=5)
plot(x,y,type="p",pch=3,lwd=x,cex=y,col=grey(1:25)/25,xlim=c(0,5),ylim=c(0,5),bty="n", ann=F)
title(main="R plottingsymbols: size and width",xlab="Width (lwd)",ylab="Size (cex)")
![Page 43: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/43.jpg)
Plot dengan built in color
tb=c(160, 165, 175, 180, 185)bb=c(55,60,70,75,80)tb=c(160, 165, 175, 180, 185)bb=c(55,60,70,75,80)
R users group An introduction to graphics in R
![Page 44: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/44.jpg)
Plotting two variables: scatterplot
plot(x=bb,y=tb)
Alternative formulations:
plot(bb~tb)
plot(x=bb,y=tb)
Alternative formulations:
plot(bb~tb)
![Page 45: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/45.jpg)
Plotting two variables: scatterplot
Different symbols, specified bypch parameter
plot(bb~tb, pch=16)
![Page 46: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/46.jpg)
Plotting two variables: scatterplot
plot(bb~tb, type=“l”)
![Page 47: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/47.jpg)
Plotting two variables: scatterplot
plot(bb~tb, type=“l”,lty=“dotted”)
![Page 48: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/48.jpg)
Types of lines, par(lty)
x<-1:10plot(x,y=rep(1,10),ylim=c(1,6.5),
type="l",lty=1,axes=F,ann=F)title(main="Line Types")
for(i in 2:6){lines(x,y=rep(i,10),lty=i)}
axis(2,at=1:6,tick=F,las=1)
linenames<-paste("Type",1:6,":",c("solid","dashed","dotted","dotdash","longdash","twodash"))
text(2,(1:6)+0.25,labels=linenames)box()
x<-1:10plot(x,y=rep(1,10),ylim=c(1,6.5),
type="l",lty=1,axes=F,ann=F)title(main="Line Types")
for(i in 2:6){lines(x,y=rep(i,10),lty=i)}
axis(2,at=1:6,tick=F,las=1)
linenames<-paste("Type",1:6,":",c("solid","dashed","dotted","dotdash","longdash","twodash"))
text(2,(1:6)+0.25,labels=linenames)box()
![Page 49: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/49.jpg)
tb=c(160, 165, 175, 180, 185)bb=c(55,60,70,75,80)tb=c(160, 165, 175, 180, 185)bb=c(55,60,70,75,80)
![Page 50: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/50.jpg)
Adding to plots: lines
plot(bb,tb)
reg<-lm(tb~bb)
abline(reg,col="red",lty=2)
plot(bb,tb)
reg<-lm(tb~bb)
abline(reg,col="red",lty=2)
![Page 51: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/51.jpg)
plot(bb,tb)reg<-lm(tb~bb)abline(reg, col="red",lty=2)abline(v=60,col="red")
plot(bb,tb)reg<-lm(tb~bb)abline(reg, col="red",lty=2)abline(v=60,col="red")
![Page 52: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/52.jpg)
Adding to plots: legendsy1=c(2, 5, 4, 5, 12)y2=c(2,3,4,5,4)plot(y1, type="o", col="blue",ylim=c(0,12),xlab="tahun",ylab="jumlah")lines(y2, type="o", pch=22, lty=2, col="red")title(main="Contoh aja", col.main="red", font.main=4)legend(1, 6, c("A","B"), cex=0.8, col=c("blue","red"), pch=21:22, lty=1:2)
y1=c(2, 5, 4, 5, 12)y2=c(2,3,4,5,4)plot(y1, type="o", col="blue",ylim=c(0,12),xlab="tahun",ylab="jumlah")lines(y2, type="o", pch=22, lty=2, col="red")title(main="Contoh aja", col.main="red", font.main=4)legend(1, 6, c("A","B"), cex=0.8, col=c("blue","red"), pch=21:22, lty=1:2)
![Page 53: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/53.jpg)
Tugas 1 (Data Mhs Stat)Nama Pek ORTU IPK Kelas Asal Daerah
Fulan PNS 3.4 A Medan
Dede PNS 2.7 A Medan
Sondakh WIRASWASTA 2.6 B Jakarta
Nurdin TNI 2.3 A Bandung
John WIRASWASTA 3.5 A Bandung
Lung WIRASWASTA 3.7 B JakartaLung WIRASWASTA 3.7 B Jakarta
Yaris WIRASWASTA 3.1 B Jakarta
Asep TNI 2.9 B Bandung
Dedi TNI 2.3 B Bandung
Zeni PNS 2.8 A Jakarta
Nia PNS 2.9 A Jakarta
Sinto PNS 3.0 B Padang
Cucu TNI 3.1 B Padang
Fika TNI 3.4 A Medan
Neo TNI 3.6 A Padang
![Page 54: graphics dalam R - zulstat.files.wordpress.com · graphics dalam R. Graphics dalam R • Graphs dibangun di R dengan dua prinsip 1) Membangun Grafik Dasar 2) Menambah infomasi pada](https://reader033.fdocuments.net/reader033/viewer/2022052314/5c7e972b09d3f2b93f8b6fef/html5/thumbnails/54.jpg)
Soal
• Dari data mahasiswa stat tersebut• Buatlah grafik yang menggambarkan
perbedaan IPK berdasarkan• A. Pekerjaan Ortu• B. Asal Daerah• C Kelas• Dari grafik tersebut perbedaan manakah yang
memiliki keseragaman yang kecil ?
• Dari data mahasiswa stat tersebut• Buatlah grafik yang menggambarkan
perbedaan IPK berdasarkan• A. Pekerjaan Ortu• B. Asal Daerah• C Kelas• Dari grafik tersebut perbedaan manakah yang
memiliki keseragaman yang kecil ?