티스토리 뷰
plot(x,y,...)
그래프로 나타내기위한 함수
변수
x
그래프에 표시될 지점 (필수값)
y
x의 값에 대응하는 y값.
* 반드시 x의 길이와 같아야한다.
> plot(1:10, 1:9) # x의 개수(10개)와 y의 개수(9개)가 일치하지 않으면 다음과 같은 에러 발생
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
type
그려지는 그래프의 형식. p(points), l(lines), b(both points and lines), o(overplotted), h(histogram), s 또는 S(steps)
-type을 명시하지 않은 경우
> head(cars)
speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10
> plot(cars)
> plot(cars$speed)
> par(mfrow=c(1,3)) # 한 화면에 3개의 그래프가 그려질 수 있도록 함
> plot(cars$speed, type="p")
> plot(cars$dist, type="l")
> plot(cars$dist, type="b")
* 한 화면에 여러개의 그래프를 그리고 싶을 때
> par(mfrow=c(1,3)) # c(행의 개수, 열의 개수)