#title Scatter Plot [[TableOfContents]] http://www.sthda.com/english/articles/32-r-graphics-essentials/130-plot-multivariate-continuous-data/ --> 이거 좋네 {{{ library("GGally") ggpairs(train[,3:13], aes(color = is_churn, alpha=0.2))+ theme_bw() }}} ==== pairs ==== {{{ library(car) spm(~Sepal.Length + Sepal.Width + Petal.Length + Petal.Width | Species, data=iris) }}} attachment:ScatterPlot/spm.png {{{ pairs(iris, col = c("red", "cornflowerblue", "purple")[iris$Species]) }}} attachment:ScatterPlot/iris_scatter.png ==== smoothScatter ==== 일반적으로 산점도(scatter plot)를 그리면 다음과 같다. {{{ plot(x,y) }}} attachment:R그래픽스-유용한예제들/smoothScatter01.png 그런데, 데이터의 양이 많으면 위와 같이 데이터의 분포를 파악하기 어렵다. smoothScatter()는 이런 어려움을 극복할 수 있게 시각화 해준다. 아래의 그림을 보면 3개 정도의 군집이 있는 것을 확인 할 수 있다. {{{ library(graphics) smoothScatter(x, y) }}} attachment:R그래픽스-유용한예제들/smoothScatter02.png ==== 3D ==== --https://www.google.com/search?q=pred.surf.3d&rlz=1C1GCEU_koKR892KR892&oq=pred.surf.3d&aqs=chrome..69i57.425j0j7&sourceid=chrome&ie=UTF-8 {{{ require(rgl) pred.surf.3d <- function(df, x.nm,y.nm,z.nm, ...){ x <- df[,x.nm]; y <- df[,y.nm]; z<-df[,z.nm] fit <- lm(z ~ x + y + x*y + x^2 + y^2) xnew <- seq(range(x)[1],range(x)[2],len=20) ynew <- seq(range(y)[1],range(y)[2],len=20) df <- expand.grid(x=xnew, y=ynew) df$z <- predict(fit, newdata=df) with(df, surface3d(xnew, ynew, z=df$z, alpha=0.5)) } plot3d(mydata$x, mydata$y, mydata$zl, col=rainbow(1000)) pred.surf.3d(mydata, "x", "y", "z") }}}