문법 익힐겸, 무의미한 데이터를 만들어서 그림을 그려본다

단순히 랜덤 값으로 data frame 을 구성하고, y축 값을 sort 해서 step 을 그리는 구문이다



# load library
library ("ggplot2")

# set data frame with x and y
# y is random from 10 to 20
d = data.frame(x=1:100, y=runif(100, min=10, max=20))

# sort data of y
d$y = sort(d$y)

# draw step
p = ggplot(d, aes(x, y))
p + geom_step()



- Download & Install R

     R Homepage
          http://www.r-project.org/

     서울대 mirror
          http://healthstat.snu.ac.kr/CRAN/


- R Studio Download
     http://www.rstudio.com/products/rstudio/download/

     R Studio 가 참 훌륭한것 같음!


- 시각화 Plugin (ggplot)
     http://docs.ggplot2.org/current/

- install ggplot
     > install.packages("ggplot2")

     - 처음에 실행해서 ggplot2 를 설치하려고 하면
     > tar: Failed to set default locale

     뭐 이런 메시지 나오는데, Mac Terminal 에
     $ defaults write org.R-project.R force.LANG en_US.UTF-8

     http://davidprakash.blogspot.kr/2011/05/r-error-tar-failed-to-set-default.html
     이렇게 하고 재시작 하면 됨..



- 간단한 그래프 그려보기
     > x = 1:1000
     > y = x^2
     > plot(x, y)

+ Recent posts