1 / 33

2013.10.03 R study

2013.10.03 R study. 6 장 , 그래프. 1. 산점도. 데이터를 점으로 흩뿌리는 형태의 시각화 Plot 함수로 그림 > Methods(plot). 실습. > install.packages (“ mlbench ”) > library( mlbench ) > Data(Ozone) > Plot(Ozone$V8, Ozone$V9). 축이름 변경. > plot(Ozone$V8, Ozone$V9, xlab =“ Sanburg Temperatuer ”,

hayden
Download Presentation

2013.10.03 R study

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2013.10.03 R study 6장, 그래프

  2. 1. 산점도 데이터를 점으로 흩뿌리는 형태의 시각화 Plot 함수로 그림 > Methods(plot)

  3. 실습 • > install.packages(“mlbench”) • > library(mlbench) • > Data(Ozone) • > Plot(Ozone$V8, Ozone$V9)

  4. 축이름 변경 • > plot(Ozone$V8, Ozone$V9, xlab=“SanburgTemperatuer”, • + ylab = “E1 Monte Temprature”) • Xlab = x축 이름 • Ylab = y축 이름

  5. 그래프 제목 • plot ( Ozone $V8 , Ozone $V9 , xlab =" Sandburg Temperature ", • + ylab ="El Monte Temperature ", main =" Ozone ") • X, Y 축 제외하고 제목만 변경할경우 • plot ( Ozone $V8 , Ozone $V9 , main =" Ozone ")

  6. 점의 종류 변경 • > plot ( Ozone $V8 , Ozone $V9 , xlab =" Sandburg Temperature ", • + ylab ="El Monte Temperature ", main =" Ozone ", pch =20) • > plot ( Ozone $V8 , Ozone $V9 , xlab =" Sandburg Temperature ", • + ylab ="El Monte Temperature ", main =" Ozone ", pch="+") • -> “” 로특수문자포함 문자열 1byte 까지만 가능한듯 • -> pch코드는 구글에서‘r pch symbol’ 키워드로 검색

  7. 점의 크기, 색상변경 • > plot ( Ozone $V8 , Ozone $V9 , xlab =" Sandburg Temperature ", • + ylab ="El Monte Temperature ", main =" Ozone ", cex=.1) • > plot ( Ozone $V8 , Ozone $V9 , xlab =" Sandburg Temperature ", • + ylab ="El Monte Temperature ", main =" Ozone ", col="# FF0000 ")

  8. X, Y 축 값의 범위 • > plot ( Ozone $V8 , Ozone $V9 , xlab =" Sandburg Temperature ", • + ylab ="El Monte Temperature ", main =" Ozone ") • > max( Ozone $V8) • [1] NA • > max( Ozone $V8 , na.rm = TRUE ) • [1] 93 • > max( Ozone $V9 , na.rm = TRUE ) • [1] 82 .58 • > plot ( Ozone $V8 , Ozone $V9 , xlab =" Sandburg Temperature ", • + ylab ="El Monte Temperature ", main =" Ozone ", • + xlim =c(0, 100) , ylim =c(0, 90))

  9. Type • plot (cars , type ="l") • Type = L type = o • + D

  10. 그래프의 배열 • > opar <- par( mfrow =c(1, 2)) • > plot ( Ozone $V8 , Ozone $V9 , xlab =" Sandburg Temperature ", • + ylab ="El Monte Temperature ", main =" Ozone ") • > plot ( Ozone $V8 , Ozone $V9 , xlab =" Sandburg Temperature ", • + ylab ="El Monte Temperature ", main =" Ozone2 ") • > par( opar) • 한창에 여러 개의 그래프나열 • 두개의 그래프를 한번에 비교할때 사용

  11. 지터 • > plot ( Ozone $V6 , Ozone $V7 , xlab =" Windspeed ", ylab =" Humidity ", • + main =" Ozone ", pch =20 , cex=.5) • > plot ( jitter ( Ozone $V6), jitter ( Ozone $V7), • + xlab =" Windspeed ", ylab =" Humidity ", main =" Ozone ", • + pch =20 , cex=.5) • jitter(x, factor = 1, amount = NULL) • -> 값을 조금씩 움직여 점이 겹치는것을 막는다 • -> 정확한 데이터를 보여주지못할것같다

  12. 지터2

  13. • > plot ( iris $ Sepal.Width , iris $ Sepal.Length , cex =.5 , pch =20 , • + xlab =" width ", ylab =" length ", main =" iris ") • > points ( iris $ Petal.Width , iris $ Petal.Length , cex =.5 , • + pch="+", col="# FF0000 ") 이미 생성된 그래프에 점을 추가 색상이나 크기조절도가능하다

  14. • > x <- seq (0, 2*pi , 0.1) • > y <- sin(x) • > plot (x, y, cex=.5 , col ="red ") • > lines (x, y) • 기존에 그려진 점위에 선을 긋는다

  15. 선2 • LOWESS는 데이터의 각 점에서 linear model(y = ax + b) 또는 quadratic model(y = ax2 + bx + c) 을 각각 적합하되, 각 점에서 가까운 데이터에 많은 weight를 주면서 regression을 수행한다. • 이렇게 만들어진 결과물은 자료의 추세를 보여주는 선이된다

  16. 직선 • plot (cars , xlim =c(0, 25) ) • abline (a=-5, b=3.5 , col ="red ") • 앞서보인cars 데이터가 dist = −5+3.5×speed로 근사될 수 있다고 가정

  17. 곡선 • 0부터 2π까지의 구간에 대한 sin 곡선 • curve (sin , 0, 2*pi)

  18. 다각형 • 선형회귀 거친후 다시 복습

  19. 문자열 • plot (cars , cex=.5) • text ( cars $speed , cars $dist , pos =4, cex =.5) • 데이터 순서에 따라 번호를 붙인다

  20. 데이터의 식별 • plot (cars , cex=.5) • identify ( cars $speed , cars $ dist ) • 마우스 클릭으로 해당점의 값을 볼수있다

  21. 범례 • > plot ( iris $ Sepal.Width , iris $ Sepal.Length , cex =.5 , pch =20 , • + xlab =" width ", ylab =" length ") • > points ( iris $ Petal.Width , iris $ Petal.Length , cex =.5 , • + pch="+", col="# FF0000 ") • > legend (" topright ", legend =c(" Sepal ", " Petal "), • + pch=c(20 , 43) , cex=.8 , col=c(" black ", "red"), bg=" gray ")

  22. 범례2

  23. > x <- seq (-2*pi , 2*pi , 0.01 ) • > y <- matrix (c( cos (x), sin (x)), ncol =2) • > matplot (x, y, col=c(" red ", " black "), cex =.2) • > abline (h=0, v =0)

  24. 상자그림 • boxplot ( iris $ Sepal.Width) • http://techntalk.tistory.com/entry/%EB%B0%95%EC%8A%A4%ED%94%8C%EB%A1%AF-Box-Plot%EA%B3%BC-%EC%A0%95%EA%B7%9C%EB%B6%84%ED%8F%ACnormal-distribution%EC%9D%98-%EA%B4%80%EA%B3%84-%EB%B0%95%EC%8A%A4%ED%94%8C%EB%A1%AF-%EA%B7%B8%EB%A6%AC%EB%8A%94-%EB%B2%95

  25. 히스토그램 • Hist(Nile) • hist ( iris $ Sepal.Width )

  26. 밀도그림 • plot ( density ( iris $ Sepal.Width)) • plot(density(Nile))

  27. 밀도그림 + 히스토그램 • > hist ( iris $ Sepal.Width , freq = FALSE ) • > lines ( density ( iris $ Sepal.Width ))

  28. 막대 그림 • barplot ( tapply ( iris $ Sepal.Width , iris $ Species , mean )) • Tapply는 ‘데이터, 그룹인덱스, 각그룹별로 호출할 함수를 받는다)

  29. 파이그래프 • Pie 함수를 이용해 그리며 데이터의 비율을 알아보는데 적합 • 구간으로 데이터를 나누기 위해서는 cut() 함수를 사용한다. • cut (1:10 , breaks =c(0, 5, 10) ) • cut (1:10 , breaks =3) • cut( iris $ Sepal.Width, breaks =10) • rep(c("a", "b", "c"), 1:3) • table ( rep(c("a", "b", "c"), 1:3) ) • table ( cut( iris $ Sepal.Width , breaks =10) ) • pie( table ( cut( iris $ Sepal.Width , breaks =10) ), cex =.7)

  30. 모자이크 플롯 • str( Titanic ) • Titanic • mosaicplot ( Titanic , color = TRUE ) • mosaicplot (∼ Class + Survived , data = Titanic , color = TRUE )

  31. 산점도 행렬 • pairs (∼ Sepal.Width + Sepal.Length + Petal.Width + Petal.Length, • data =iris , col=c("red", " green ", " blue ")[ iris $ Species ])

  32. 투시도 • X 그리드, Y 그리드, 그리고 각 grid 점에서의 Z 값을 인자로 받는다.

  33. 등고선 • contour (x, y, outer (x, y, f))

More Related