본문 바로가기

공부와 공부와 공부/R

5-1 다변량 자료의 탐색 - 산점도 plot(), pch(), pairs()

다변량 자료다변량 자료의 탐색 

  • 분석하려는 주제가 두 개 이상인 것
  • 변수가 두 개인 경우는 이변량 자료
  • 이변량 자료 분석이 많음
  • 2차원 형태의 배열에 넣어서 분석
  • 분석 대상이 되는 주제가 변수

 

변수는 데이터셋에서 열로 표현 

 

산점도 plot()

 

이변량 자료의 분포 및 상관관계를 시각적으로 보여줌

변수의 상관관계를 확인할 수 있음

 

wt<-mtcars$wt

mpg<-mtcars$mpg

plot(wt, mpg,

     main="car weight-mpg",

     xlab="car weight",

     ylab="miles per callon",

     col="red",

     pch=19)

 

 

 

산점도의 매개변수

 

 

포인트의 종류

plot()

 

2차원 그래프

두 개의 변수에 대한 관계만 나타냄

 

 

pairs()

 

여러 변수들 사이의 상관관계를 한꺼번에 나타냄

 

vars<-c("mpg","disp","drat","wt")

target<-mtcars[,vars]

pairs(target,

      main="Multi plots")

 

 

그룹별로 다른 컬러 및 모양의 포인트 사용 

 

iris.2<-iris[,3:4]

point<-as.numeric(iris$Species)

color<-c("red","green","blue")

plot(iris.2,

     main="Iris plot",

     pch=c(point),

     col=color[point])