갈루아의 반서재

이번에 알아볼 것은 산포도(Scatter Plot) 그리는 방법입니다. 

먼저 아래 내용을 정해야 합니다. 각각의 단계에 코드를 대응시켜보면 다음과 같습니다. 


1) x, y 축 결정

> xlim = range(x)

> ylim = range(y)


2) 좌표창 로딩

> plot.new()

> plot.window(xlim = xlim, ylim = ylim)


3) 점 배치

> points(x, y)


아래와 같이 산포도 함수를 하나 만듭니다. 


> scat = function(x, y) {

xlim = range(x) // range returns a vector containing the minimum and maximum of all the given arguments.

ylim = range(y)

plot.new()

plot.window(xlim = xlim, ylim = ylim)

points(x, y)

axis(1) // axis adds an axis to the current plot. The axis is placed as follows: 1=below, 2=left, 3=above and 4=right.

axis(2)

box()

}


> xv = 1:100

> yv = rnorm(100) // rnorm function which can generate random numbers whose distribution is normal

> scat(xv, yv) 

> title(main = "A Scatter Plot")