r graphics by novi reandy sasmita

14
R Graphics Practice and Theory Monday, March 26, 2012 Novi Reandy Sasmita [email protected] http://www.researchgate.net/profile/Novi_Sasmita

Upload: beasiswa

Post on 04-Aug-2015

181 views

Category:

Education


0 download

TRANSCRIPT

Page 1: R graphics by Novi Reandy Sasmita

R GraphicsPractice and TheoryMonday, March 26, 2012

Novi Reandy [email protected]://www.researchgate.net/profile/Novi_Sasmita

Page 2: R graphics by Novi Reandy Sasmita

R Graphics: Data

Page 3: R graphics by Novi Reandy Sasmita

R Graphics: Data> indicators=c("Total Assets (trillions of 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 (%)")> data2001=c(1099.7, 797.4, 358.6, 45.0, 1.4, 12.1, 20.5)> data2000=c(1030.5, 699.1, 320.5, 45.8, 0.9, 18.8, 12.7)> data2001=c(1099.7, 797.4, 358.6, 45.0, 1.4, 12.1, 20.5)> data2002=c(1112.2, 853.8, 410.3, 49.1, 1.9, 8.1, 22.5)> data2003=c(1196.2, 888.6, 477.2, 53.7, 2.5, 8.2, 19.4)> data2004=c(1272.3, 963.1, 596.1, 61.8, 3.5, 5.8, 19.4)> data2005=c(1469.8, 1127.9, 730.2, 64.7, 2.6, 8.0, 19.5)> data2006=c(1693.5, 1287.0, 832.9, 64.7, 2.6, 6.1, 20.5)> data2007=c(1986.5, 1510.7, 1045.7, 69.2, 2.8, 4.1, 19.2)> data2008=c(2310.6, 1753.3, 1353.6, 77.2, 2.3, 3.2, 16.8)> data2009=c(2534.1, 1973.0, 1437.9, 72.8, 2.6, 3.3, 17.4)> bank=data.frame(indicators, data2000, data2001, data2002, data2003, data2004, data2005, data2006, data2007, data2008, data2009)

Page 4: R graphics by Novi Reandy Sasmita

R Graphics: Plot# Make data to be matrix and remove the first coloumb of bankbank_1=as.matrix(bank[,-1])

# Graph the first row of bank_1 vector with 10 valueplot(bank_1[1,])

2 4 6 8 10

1000

1500

2000

2500

Index

bank

_1[1

, ]

Page 5: R graphics by Novi Reandy Sasmita

R Graphics: Plot#Define bank_1[1,] with name total assettotal_asset= bank_1[1,]

# Graph total_asset using blue points overlayed by a lineplot(total_asset, type=“o”, col=“blue”)

#Create a title with a red, blod/italic fonttitle(main="Total Assets (trillions of Rp)", col.main="red", font.main=4)

2 4 6 8 10

1000

1500

2000

2500

Indexto

tal_

asse

t

Total Assets (trillions of Rp)

Page 6: R graphics by Novi Reandy Sasmita

R Graphics: Line Chart# Compute the largest y value used in the data (or we could just

use range again)> max_y=max(bank_1)

# Define colors to be used for tree data> plot_warna=c("blue","red","green")

# Graph bank_1 using y axis that ranges from 0 to max_y# Turn off axes and annotations (axis labels) so we can# specify them ourself> plot(bank_1[1,], type="o",col=plot_warna[1],ylim=c(0,max_y),axes=FALSE, ann=FALSE)

# Make x axis using 2000-2009 labels> axis(1, at=1:10, lab=c("2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009"))

# 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)

2000 2001 2002 2003 2004 2005 2006 2007 2008 2009

0

250

500

750

1000

1250

1500

1750

2000

2250

2500

Indicators of the Condition of Comercial Banks in Indonesia,2000-2009

Years

Trill

ions

Total AssetDepositesCredits

Page 7: R graphics by Novi Reandy Sasmita

R Graphics: Line Chart# Create box around plot> box()

# Graph Deposites with red dashed line and square points> lines(bank_1[2,], type="o", pch=22, lty=2, col=plot_warna[2])

# Graph Credits with green dotted line and diamond points > lines(bank_1[3,], type="o", pch=23, lty=3, col=plot_warna[3])

# Create a title with a red, bold/italic font> title(main="Indicators of the Condition of Comercial Banks in Indonesia,2000-2009", col.main="red", font.main=4)

# Label the x and y axes with dark green text> title(xlab="Years", col.lab=rgb(0,0.5,0))> title(ylab="Trillions", col.lab=rgb(0,0.5,0))

2000 2001 2002 2003 2004 2005 2006 2007 2008 2009

0

250

500

750

1000

1250

1500

1750

2000

2250

2500

Indicators of the Condition of Comercial Banks in Indonesia,2000-2009

Years

Trill

ions

Total AssetDepositesCredits

Page 8: R graphics by Novi Reandy Sasmita

R Graphics: Line Chart# Create a legend at (2400)# (cex) and uses the same line colors and points used by # the actual plots> legend(2400,c("Total Asset","Deposites","Credits"), cex=0.8, col=plot_warna, pch=21:23, lty=1:3)

2000 2001 2002 2003 2004 2005 2006 2007 2008 2009

0

250

500

750

1000

1250

1500

1750

2000

2250

2500

Indicators of the Condition of Comercial Banks in Indonesia,2000-2009

Years

Trill

ions

Total AssetDepositesCredits

Page 9: R graphics by Novi Reandy Sasmita

R Graphics: Boxplot# make graph with bank_1> boxplot(bank_1)

data2000 data2001 data2002 data2003 data2004 data2005 data2006 data2007 data2008 data2009

050

010

0015

0020

0025

00

Page 10: R graphics by Novi Reandy Sasmita

R Graphics: Histogram# Graph autos with adjacent bars using rainbow colors> hist(bank_1[,1], col="green", main="Data 2000", xlab="Trillions")

Data 2000

Trillions

Freq

uenc

y0 200 400 600 800 1000 1200

01

23

4

Page 11: R graphics by Novi Reandy Sasmita

R Graphics: Barplot# Graph autos with adjacent bars using rainbow colors> barplot(bank_1, main="Indicators of the Condition of Comercial Banks in Indonesia,2000-2009",ylab="Trillions", beside=TRUE, col=rainbow(7))

# Place the legend at the top-left corner with no frame # using rainbow colors> legend("topleft",c("Total Assets (trillions of 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 (%)"),cex=0.8,bty="n", fill=rainbow(7))

data2000 data2002 data2004 data2006 data2008

Indicators of the Condition of Comercial Banks in Indonesia,2000-2009

Trill

ions

050

010

0015

0020

0025

00

Total Assets (trillions of 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 (%)

Page 12: R graphics by Novi Reandy Sasmita
Page 13: R graphics by Novi Reandy Sasmita

R Graphics: Piechart# Define total suara vector with 4 values> total_suara=c(46442,101325,189858,128230)

# Define some colors ideal for total suara> warna=rainbow(length(total_suara))

# Calculate the percentage for candidate, rounded to one# decimal place> persentasi=round(total_suara/sum(total_suara)*100,1)

# Concatenate a '%' char after each value> persentasi=paste(persentasi, "%", sep="")

# 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)

10%

21.8%

40.8%

27.5%

Persentasi Total Suara

1234

Page 14: R graphics by Novi Reandy Sasmita

R Graphics: Dotchart# Create a colored dotchart for bank_1 with smaller labels> dotchart(t(bank_1), color=rainbow(length(bank_1)), main="Indicators of the Condition of Comercial Banks in Indonesia,2000-2009",cex=0.8)

data2000data2001data2002data2003data2004data2005data2006data2007data2008data2009

data2000data2001data2002data2003data2004data2005data2006data2007data2008data2009

data2000data2001data2002data2003data2004data2005data2006data2007data2008data2009

data2000data2001data2002data2003data2004data2005data2006data2007data2008data2009

data2000data2001data2002data2003data2004data2005data2006data2007data2008data2009

data2000data2001data2002data2003data2004data2005data2006data2007data2008data2009

data2000data2001data2002data2003data2004data2005data2006data2007data2008data2009

1

2

3

4

5

6

7

0 500 1000 1500 2000 2500

Indicators of the Condition of Comercial Banks in Indonesia,2000-2009