Presentation is loading. Please wait.

Presentation is loading. Please wait.

강의 4 R Graphics _2.

Similar presentations


Presentation on theme: "강의 4 R Graphics _2."— Presentation transcript:

1 강의 4 R Graphics _2

2 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (1) mfrow(), mfcol(), layout(), split.screen() : 화면분할 인수 par(mfrow=c(2,3)) # 그래픽윈도 화면 분할 # 기본값은 mfrow=c(1, 1) 과 mfcol=c(1, 1) cars <- read.table("E:\\work\\cars.txt", header=T) cars m <- matrix(c(1,1,2,3), ncol=2, byrow=T) m [,1] [,2] [1,] [2,] layout(mat=m) plot(cars, main="Scatter plot of cars data") hist(cars$speed) hist(cars$dist) layout.show R Graphics : Device 2 (ACTIVE)

3 R 그래픽스 4 : par 함수 parameter(인수) functions (1) mfrow(), mfcol(), layout(), split.screen() : 화면분할 인수
par(bg="white") #바탕색 흰색으로 지정 split.screen(fig=c(2,1)) # 상하 2개로 화면분할 [1] ( fig인수=행열로 주어진 대로) split.screen(c(1,2), screen=2) #아래 2번 화면을 [1] 좌우 2개로 분할 screen(n=3) # 3번 화면(아래 왼쪽)을 지정 cars <- read.table("E:\\work\\cars.txt", header=T) hist(cars$dist) screen(1) # 1번 화면(위쪽)을 지정 plot(cars, main="Scatter Plot of Cars Data by split.screen") screen(4) # 4번 화면(아래 오른쪽)을 지정 hist(cars$speed) erase.screen(n=1) #1번 화면 지움 screen(1) split.screen") close.screen(all=TRUE) #화면분할 정의 마침 R Graphics : Device 2 (ACTIVE)

4 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (2) fig(), new(), bty(), pty() 인수
cars <- read.table("E:\\work\\cars.txt", header=T) par(mfrow=c(2,2)) par(fig=c(0,1,0.5,1)) + # default는 c(x1=0, x2=1, y1=0, y2=1):화면전체 plot(cars, main="scatter plot of cars data by fig") par(fig=c(0, 0.5, 0, 0.5), new=T) hist(cars$speed, main= "Histogram of cars$speed by fig") par(fig=c(0.5, 1, 0, 0.5), new=T) hist(cars$dist, main="Histogram of cars$dist by fig") # 세 개의 그래프를 한 그래프화면에 그리기 위해서 new 인수를 TRUE로 변경했다. R Graphics : Device 2 (ACTIVE)

5 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (2) fig(), new(), bty(), pty() 인수
new() 인수는 다음 번 고수준그래픽함수가 호출될 때, Figure region의 내용을 초기화 하는지 여부를 결정한다. 기본값은 FALSE이며 이때는 고수준그래픽 함수가 호출 될 때 Figure region의 내용을 초기화한다. par(mfrow=c(2,2)) plot(1:10,type="l", main="plot") par(new=F) plot(10:1,type="s", main="plot by new=F") plot(1:10,type="l") par(new=T) plot(10:1,type="s", main="plot by new=T") x <- rnorm(10) plot(x) hist(x) R Graphics : Device 2 (ACTIVE)

6 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (2) fig(), new(), bty(box type) , pty() 인수
par(mfrow=c(2,3), bty="l") plot(0:6, 0:6, bty="c", main=" bty=\"c\"") plot(0:6, 0:6, bty="n", main=" bty=\"n\"") plot(0:6, 0:6, bty="o", main=" bty=\"o\"") plot(0:6, 0:6, bty="7", main=" bty=\"7\"") plot(0:6, 0:6, bty="u", main=" bty=\"u\"") plot(0:6, 0:6, main=" bty=\"u\"") # default는 “o” R Graphics : Device 2 (ACTIVE)

7 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (2) fig(), new(), bty(), pty(plot type) 인수
Plot Region의 형태를 지정 “s”=squre ; “m”=maximal theta <- seq(-pi, pi, length=30) x <- cos(theta) y <- sin(theta) par(mfrow=c(1,2), pty="s", bty="o") plot(x, y, type="l", main="pty=\"s\"") par(pty="m") plot(x, y, type="l", main="pty=\"m\"") R Graphics : Device 2 (ACTIVE)

8 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (3) type(), pch(), lty(), xlab(x-axis labels), ylab, xlim(x-axis limits), ylim R Graphics : Device 2 (ACTIVE) par(mfrow=c(2,3), type="n") plot(0:6, 0:6, main="default") plot(0:6, 0:6, type="b", main="type=\"b\"") plot(0:6, 0:6, type="c", main="type=\"c\"") plot(0:6, 0:6, type="o", main="type=\"o\"") plot(0:6, 0:6, type="s", main="type=\"s\"") plot(0:6, 0:6, type="S", main="type=\"S\"") x <- 0:4 (y <- dbinom(x, size=4, prob=0.5) ) [1] par(oma=c(0,0,2,0), mfrow=c(2,2)) plot(x,y,type="h", main="default") plot(x,y,type="h", ylim=c(0,max(y)), main="ylim=c(0,max(y))") plot(x,y,type="h", ylim=c(0.1,0.3), main="ylim=c(0.1,0.3)") plot(x,y,type="h", xlim=c(1,3), main="xlim=c(1, 3)") title(main="binomial density", line=0, outer=T)

9 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (4) col(color), cex(), srt(), tck(), tcl() 인수
col.table <- function(cols) { n=length(cols) plot(seq(n), rep(1,n), xlim=c(0,n), ylim=c(0,1), type="n“, xlab="", ylab="", axes=F) + title(paste("Color Table by", deparse(substitute(cols)))) + for(i in 1:n) { + polygon(c(i-1, i-1, i, i), c(0.05, 1, 1, 0.05), col=cols[i]) + text(mean(c(i-1,i)), 0.52, labels=cols[i], srt=90, adj=0.5) } + } par(mfrow=c(4,1), mar=c(0,0,2,0)) col.table(1:16) col.table(5:20) col.table(rainbow(20)) col.table(heat.colors(20)) R Graphics : Device 2 (ACTIVE)

10 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (4) col(color), cex(), srt(), tck(), tcl() 인수
win.graph() par(mfrow=c(4,1), mar=c(0,0,2,0)) col.table(terrain.colors(20)) col.table(topo.colors(20)) col.table(cm.colors(20)) col.table(colors()[1:20]) R Graphics : Device 2 (ACTIVE)

11 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (4) col(), cex(character expansion), srt(), tck(), tcl() 인수 cex(character expansion)는 문자나 점의 크기 결정. 기본값은 1 이다. par(mfrow=c(2,2), oma=c(0,0,2,0), cex=1) plot(0:6, 0:6, type="n", main="cex in text") text(1:3, 1:3, labels=LETTERS[1:3], cex=1:3) plot(0:6, 0:6, type="n", cex=2, main="cex in plot") par(cex=1.2) plot(0:6, 0:6, type="n", main="cex in par") text(1:3, 1:3, labels=c("가","나","다"), cex=1:3) points(3:5, 1:3, pch=1:3, cex=1:3) title(main="cex", line=0, outer=T) R Graphics : Device 2 (ACTIVE)

12 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (4) col(), cex(), srt(string rotation), tck(), tcl() 인수 R Graphics : Device 2 (ACTIVE) srt(string rotation) 는 문자열을 회전하여 출력. 기본값은 0 도(전체360도) 이다. par("srt") [1] 0 plot(0:6, 0:6, type="n", axes=F, xlab="", ylab="") text(3, 5, "srt=0", srt=0, cex=2) text(1, 3, "srt=90", srt=90, cex=2) text(3, 1, "srt=180", srt=180, cex=2) text(5, 3, "srt=270", srt=170, cex=2) text(5, 3, "srt=270", srt=270, cex=2) text(5, 5, "srt=-45", srt=-45, cex=2) text(1, 5, "srt=45", srt=45, cex=2) points(3,3, pch="A", srt=45, cex=2) title("srt", srt=45) mtext(side=2, "srt=270", srt=270, cex=2) axis(side=1, srt=45)

13 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (5) mar(margin), oma(), family, font, fg, bg 인수
par(mfrow=c(2,2)) par("mar") [1] # default=c(5,4,4,2)+0.1 #(side1, side2, side3, side4) # c(下, 左, 上, 右) # x축 y축 title 여백 # Figure 1 par(mar=c(0,0,0,0)) # c(下, 左, 上, 右) plot(0:4, 0:4) #Figure 2 par(mar=c(2,2,2,2)) plot(0:4, 0:4, main="mar=c(2,2,2,2)") #Figure 3 par(mar=c(5,5,5,5)) plot(0:4, 0:4, main="mar=c(5,5,5,5)") # Figure 4 par(mar=c(1,2,3,4)) plot(0:4, 0:4, main="mar=c(1,2,3,4)") R Graphics : Device 2 (ACTIVE)

14 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (5) mar(margin), oma(), family, font, fg, bg 인수
plot(1:10, type="n", main="par(font)") lab <- "Written with font parameter “ for (i in 1:10) { par(font=i) text(1, 11-i, labels=paste(lab, i), adj=0, cex=1.5) + } unlist(par("fg", "bg")) # 기본값 확인 fg bg # forward/back - ground "black" "transparent" par(bg="thistle", fg="blue") hist(rnorm(30), main="bg=\"thistle\", fg=\"blue\"") R Graphics : Device 2 (ACTIVE)

15 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (1) mfrow(), mfcol(), layout(), split.screen() : 화면분할 인수 R Graphics : Device 2 (ACTIVE)

16 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (1) mfrow(), mfcol(), layout(), split.screen() : 화면분할 인수

17 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (1) mfrow(), mfcol(), layout(), split.screen() : 화면분할 인수

18 R 그래픽스 4 : par 함수의 인수들 parameters of par() functions (1) mfrow(), mfcol(), layout(), split.screen() : 화면분할 인수


Download ppt "강의 4 R Graphics _2."

Similar presentations


Ads by Google