본문 바로가기

Data Analytics

plot( cars, main ="", xlab="", ylab="", type="n")



기본형식

> plot(x,y, type="n")

> grid()

> points(x,y)



> plot(cars, 

+      main="cars: Speed vs. Stopping Distance (1920)", 

+      xlab="Speed (MPH)", 

+      ylab="Stopping Distance (ft)",

+      type="n")

# 기본 x, y 축 그래프를 셋팅한다. 

#cf. 줄바꿈은 Shift+Enter 를 눌러주면 된다. 



> grid()

# 격자를 추가하여 그린다. 


> points(cars)

# 실제로 점을 찍어 준다. 



> with(iris, plot(Petal.Length, Petal.Width, pch=as.integer(Species)))

> legend(1.5, 2.4, c("setosa", "versicolor", "virginica"), pch=1:3)

> legend(1.5, 2.4, c("setosa", "versicolor", "virginica"), 1:3)



# factor (요인) 들이 자동으로 맞춰진다.

> with(iris, plot(Petal.Length, Petal.Width, pch=as.integer(f)))

> legend(1.5, 2.4, as.character(levels(f)), pch=1:length(levels(f)))

                #범례의 좌측상단지점의 좌표이다.  1.5, 2.4



> legend(1.5, 2.4, c("Estimate", "Lower conf lim", "Upper conf lim"), 

+                    lty=c("solid", "dashed", "dotted"))


legend 함수로 색상, 채우기, 선 두께에 대한 범례도 만들 수 있다고 한다. 

자세한 내용은 










'Data Analytics' 카테고리의 다른 글

R script 20140129  (0) 2014.01.30
kmeans in R  (0) 2014.01.30
http://www.r-tutor.com/  (0) 2014.01.29
shinyUI(pageWithSidebar  (0) 2014.01.29
R practice script 20140128  (0) 2014.01.29