Booking open Available Pune Call Girls Wadgaon Sheri 6297143586 Call Hot Ind...
R graphics by Novi Reandy Sasmita
1. R Graphics
Practice and Theory
Monday, March 26, 2012
Novi Reandy Sasmita
novireandysasmita@gmail.com
http://www.researchgate.net/profile/Novi_Sasmita
4. R Graphics: Plot
# Make data to be matrix and remove the first coloumb of bank
bank_1=as.matrix(bank[,-1])
# Graph the first row of bank_1 vector with 10 value
2500
plot(bank_1[1,])
2000
bank_1[1, ]
1500
1000
2 4 6 8 10
Index
5. R Graphics: Plot
#Define bank_1[1,] with name total asset
total_asset= bank_1[1,]
Total Assets (trillions of Rp)
2500
# Graph total_asset using blue points overlayed by a line
plot(total_asset, type=“o”, col=“blue”)
#Create a title with a red, blod/italic font
2000
title(main="Total Assets (trillions of Rp)", col.main="red",
total_asset
font.main=4)
1500
1000
2 4 6 8 10
Index
6. R Graphics: Line Chart
# Compute the largest y value used in the data (or we could just
use range again)
Indicators of the Condition of Comercial Banks in Indonesia,2000-2009
> max_y=max(bank_1)
2500
# Define colors to be used for tree data 2250
Total Asset
Deposites
Credits
> plot_warna=c("blue","red","green") 2000
1750
# Graph bank_1 using y axis that ranges from 0 to max_y
1500
# Turn off axes and annotations (axis labels) so we can
Trillions
1250
# specify them ourself
> plot(bank_1[1,], 1000
type="o",col=plot_warna[1],ylim=c(0,max_y),axes=FALSE, 750
ann=FALSE)
500
250
# Make x axis using 2000-2009 labels
0
> axis(1, at=1:10, lab=c("2000", "2001", "2002", "2003", "2004",
"2005", "2006", "2007", "2008", "2009")) 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
Years
# Make y axis with horizontal labels that display ticks at
# every 250 marks. 250*0:max_y is equivalent to c(250,500,750,…).
> axis(2,las=1,at=250*0:max_y)
7. R Graphics: Line Chart
# Create box around plot
> box() Indicators of the Condition of Comercial Banks in Indonesia,2000-2009
2500
# Graph Deposites with red dashed line and square points 2250
Total Asset
Deposites
Credits
> lines(bank_1[2,], type="o", pch=22, lty=2, col=plot_warna[2]) 2000
1750
# Graph Credits with green dotted line and diamond points 1500
Trillions
> lines(bank_1[3,], type="o", pch=23, lty=3, col=plot_warna[3]) 1250
1000
# Create a title with a red, bold/italic font 750
500
> title(main="Indicators of the Condition of Comercial Banks in
Indonesia,2000-2009", col.main="red", font.main=4) 250
0
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
# Label the x and y axes with dark green text
Years
> title(xlab="Years", col.lab=rgb(0,0.5,0))
> title(ylab="Trillions", col.lab=rgb(0,0.5,0))
8. R Graphics: Line Chart
# Create a legend at (2400)
# (cex) and uses the same line colors and points used by Indicators of the Condition of Comercial Banks in Indonesia,2000-2009
# the actual plots 2500
> legend(2400,c("Total Asset","Deposites","Credits"), cex=0.8, 2250
Total Asset
Deposites
Credits
col=plot_warna, pch=21:23, lty=1:3) 2000
1750
1500
Trillions
1250
1000
750
500
250
0
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
Years
9. R Graphics: Boxplot
# make graph with bank_1
2500
> boxplot(bank_1)
2000
1500
1000
500
0
data2000 data2001 data2002 data2003 data2004 data2005 data2006 data2007 data2008 data2009
10. Data 2000
R Graphics: Histogram
4
# Graph autos with adjacent bars using rainbow colors
> hist(bank_1[,1], col="green", main="Data 2000",
xlab="Trillions")
3
Frequency
2
1
0
0 200 400 600 800 1000 1200
Trillions
11. R Graphics: Barplot
# Graph autos with adjacent bars using rainbow colors
Indicators of the Condition of Comercial Banks in Indonesia,2000-2009
> barplot(bank_1, main="Indicators of the Condition of
2500
Comercial Banks in Indonesia,2000-2009",ylab="Trillions", Total Assets (trillions of Rp)
Deposits(trillions of Rp)
beside=TRUE, col=rainbow(7)) Credit (trillions of Rp)
loan to Deposit Ratio-LDR (%)
Return on Assets-ROA (%)
2000
Non Performing Loans-NPL (%)
Capital Adequacy Ratio-CAR (%)
# Place the legend at the top-left corner with no frame # using
1500
rainbow colors
Trillions
> legend("topleft",c("Total Assets (trillions of
1000
Rp)","Deposits(trillions of Rp)","Credit (trillions of Rp)", "loan
to Deposit Ratio-LDR (%)","Return on Assets-ROA (%)", "Non
Performing Loans-NPL (%)","Capital Adequacy Ratio-CAR
500
(%)"),cex=0.8,bty="n", fill=rainbow(7))
0
data2000 data2002 data2004 data2006 data2008
12.
13. R Graphics: Piechart Persentasi Total Suara
# Define total suara vector with 4 values
> total_suara=c(46442,101325,189858,128230) 1
21.8%
2
# Define some colors ideal for total suara 3
> warna=rainbow(length(total_suara)) 4
10%
# Calculate the percentage for candidate, rounded to one
# decimal place
> persentasi=round(total_suara/sum(total_suara)*100,1) 40.8%
# Concatenate a '%' char after each value
> persentasi=paste(persentasi, "%", sep="")
27.5%
# Create a pie chart with defined heading and custom colors #
and labels
> pie(total_suara, main="Persentasi Total Suara", col=warna,
labels=persentasi, cex=0.8)
# Create a legend at the right
> legend("topright", c("1","2","3","4"),cex=1.7, fill=warna)
14. R Graphics: Dotchart 1
data2009
data2008
data2007
data2006
Indicators of the Condition of Comercial Banks in Indonesia,2000-2009
data2005
# Create a colored dotchart for bank_1 data2004
data2003
data2002
data2001
data2000
with smaller labels 2
data2009
data2008
data2007
data2006
> dotchart(t(bank_1),
data2005
data2004
data2003
data2002
data2001
data2000
color=rainbow(length(bank_1)), 3
data2009
data2008
data2007
main="Indicators of the Condition of data2006
data2005
data2004
data2003
data2002
Comercial Banks in Indonesia,2000-
data2001
data2000
4
data2009
data2008
2009",cex=0.8) data2007
data2006
data2005
data2004
data2003
data2002
data2001
data2000
5
data2009
data2008
data2007
data2006
data2005
data2004
data2003
data2002
data2001
data2000
6
data2009
data2008
data2007
data2006
data2005
data2004
data2003
data2002
data2001
data2000
7
data2009
data2008
data2007
data2006
data2005
data2004
data2003
data2002
data2001
data2000
0 500 1000 1500 2000 2500