반응형

/*********************************************************************************************************
-- Title : [R3.3] Visualization - 연속변수 시각화
-- Reference : hrd-net
-- Key word : R 시각화 그래프 상자 박스 히스토그램 산점도 차트 boxplot hist histogram plot graph

*********************************************************************************************************/

-- Chart


-- R

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
   
# ********************************************
# -- 연속변수 시각화
#    이산변수 : 정수, 연속변수 : 실수 
#    주로 상자/히스토그램/산점도 차트로 표 
# ********************************************
 
# -- RSADBE 패키지 호출
par(mfrow=c(1,1))
library(RSADBE)
data(resistivity)                           # RSADBE패키지에서 제공하는 데이터셋
class(resistivity) 
resistivity 
 
summary(resistivity)
 
# -- 상자 그래프 시각화
boxplot(resistivity, range=0)               # 두 Process 상자 그래프 시각화
 
boxplot(resistivity, range=0, notch=T) 
# notch=T : 중위수 비교시 사용되는 옵션
 
abline(h=0.140, lty=3# 기준선 추가
 
 
# -- 히스토그램 시각화
install.packages("psych")
library(psych)
data(galton)                                # 자식과 부모의 키 사이의 관계 
 
head(galton)                                # psych 패키지 제공 데이터 셋
str(galton)
 
par(mfrow=c(1,2))
 
hist(galton$parent,breaks="FD", xlab="Height to Parent",
     main="Histogram for Parent Height with Freedman-Diaconis",
     xlim=c(60,75))                         # breaks="FD" : Freedman-Diaconis, 구간 너비
 
hist(galton$parent,breaks="Sturges", xlab="Height to Parent",
     main="Histogram for Parent Height with Sturges",
     xlim=c(60,75))                         # breaks="Sturges"  : 구간 너비
 
hist(galton$child, xlab="Height to Child",
     main="Histogram for Child Height with Freedman-Diaconis",
     xlim=c(60,75), col="mistyrose")        # col="mistyrose" : 색상(흐릿한 장미) 적용
 
hist(galton$child, xlab="Height to Child",
     main="Histogram for Child Height with Sturges",
     xlim=c(60,75), col="magenta")          # col="magenta" : 색상(진홍색) 적용
 
 
# -- 산점도 시각화
price = runif(10, min=1, max=100)           # 난수 발생
price
 
par(mfrow=c(1,1)) 
plot(price)
 
par(mfrow=c(2,2)) 
plot(price, type="l")                       # 유형 : 실선
plot(price, type="o")                       # 유형 : 원형과 실선
plot(price, type="h")                       # 직선
plot(price, type="s")                       # 꺾은선
 
# -- plot() 함수 속성 : pch : 연결점 문자타입-> plotting characher-번호(1~30)
plot(price, type="o", pch=5)                # 빈 사각형
plot(price, type="o", pch=15)               # 채워진 마름모
plot(price, type="o", pch=20, col="blue"
plot(price, type="o", pch=20, col="orange", cex=1.5
 
plot(price, type="o", pch=20, col="green", cex=2.0, lwd=3

cs

반응형

+ Recent posts