시각화 구현 개요
빅데이터 시각화 구현
- 시각화함으로써 데이터의 분포와 성격에 대해 한 눈에 알기 쉬워 인사이트를 얻기 좋다
대표적 시각화 방법
- 시각화 플랫폼
- 전문 시각화, 시각적 분석 플랫폼은 주로 BI, 인텔리전스 분야에서 사용
기업별 대표 제품
- IBM : 코그노스 인사이트, 인포메이션 빌더스
- MS : 파워피벗, 파워뷰
- 마이크로스트레터지 : 비주얼 인사이트
- 오라클 : 오라클 비즈니스 인텔리전스 엔터프라이즈 에디션
- 클릭테크 : 클릭뷰
- SAP : 비주얼 인텔리전스
- SAS : SAS 인터프라이즈 비즈니스 인텔리전스
- 그외 : 타블로, 팁코 스폿파이어 애널리틱스
기존 BI 플랫폼 : 주로 데이터 분석, 마이닝 기법을 통해 일정한 방식의 결과리포트를 생성하기 위해 시각화 기술을 활용
전문 시각화 플랫폼 : 지식 시각화 관점에서 데이터 시각화 기능 지원
적용 방법 : 플랫폼 설치, 구축 필요
- Gephi : 수많은 edge와 노드로 이루어져 복잡한 네트워크 형태를 시각화
- 시각화 라이브러리
- 라이브러리를 설치해 제공하는 API로 코드 작성
- 도구 리스트
- 인포그래픽스
- 웹서비스 형태로 제공, 제공되는 템플릿으로 구현
- ICHART, Visual.ly, Visualize FREE 등
분석 도구를 이용한 시각화 구현
그래프 작성
xy그래프
- 기본 XY그래프
- 전체적 내용 파악, 수많은 데이터가 있을 때 파악하기 어려움
- 데이터를 넣고 x,y축 지정 후 color구분하는 코드
1
|
ggplot(chickweight, aes(x=Time,y=weight, colour = Diet, group=Chick))+geom_line()
|
- aes : xy축 지정, 색과 그룹별 지정 가능
- geom_line : 선그래프를 그리는 함수
- 포인트 그래프
1
2
|
h = ggplot(chickweight, aes(x=Time,y=weight, colour = Diet))
h + geom_point(alpha=.3)
|
- 위에서 투명도를 0.3으로 조정
- 스무스 그래프
1
2
|
h = ggplot(chickweight, aes(x=Time,y=weight, colour = Diet))
h + geom_smooth(alpha=.4, size=3)
|
- 개선된 그래프(포인트+스무스)
1
|
ggplot(chickweight, aes(x=Time,y=weight, colour = Diet)) + geom_point(alpha=.3) + geom_smooth(alpha=.4, size=3)
|
히스토그램
1
2
|
ggplot(subset(chickweight, Time=21), aes(x=weight,fill= Diet)) + geom_histogram(colour=:black,bidwidth=50)
+ facet_grid(Diet ~.)
|
- Time변수가 21인 것만 선택, weight 간격 50
- facet_grid(Diet ~.)는 가로로 출력, facet_grid(.~ Diet)는 세로로 출력
포인트 그래프
1
2
3
4
|
p = qplot(wt,mpg,colour=hp, data=mtcars)
p+coord_cartesian(ylim=c(0,40))
p+scale_colour_continuous(breaks=c(100,300))
p+guides(colour = "colourbar")
|
-> y축 범위 지정, hp범위 지정, hp수치에 따른 칼라바
- 치환 데이터를 이용한 포인트 그래프
- 일정 데이터만 그릴 때, 데이터가 많으면 복잡성이 올라가고 파악이 불가능한 경우가 발생
- 10건 만 추출, p에 m을 설정
1
2
|
m = mtcars[1:10,]
p% + %m
|
막대 그래프
- 기본 막대 그래프
- 범주형 데이터를 factor로 변환
1
2
|
c = ggplot(mtcars,aes(factor(cyl)))
c+geom_bar()
|
1
|
c+ geom_bar(fill="white",colour="red")
|
-
막대 내부는 white 테두리 색은 red
-
히스토그램 형식에 적용
1
2
3
|
m=ggplot(movies, aes(x=rating))
m+geom_histogram()
m+geom_histogram(aes(fill=..count..))
|
선그래프
1
2
|
b = ggplot(economics,aes(x=date,y=unemploy))
b+geom_line()
|
1
2
|
b = ggplot(economics,aes(x=date,y=unemploy))
b+geom_line(colour="blue",size=0.3, linetype=0.3)
|
linetype : 선의 종류
효과주기
- 기본 효과 주기
- 히스토그램 : 그래프화 할 때 히스토그램으로 커트 등급 별로 나타냄
1
2
|
k = ggplot(diamonds, aes(caret,..density..)) + geom_histogram(binwidth=0.2)
k+facet_grid(.~cut)
|
facet_grid(.~cut) : caret종류를 그래프 위쪽에 표시
1
2
3
|
w = ggplot(diamonds, aes(clarity, fill=cut))
w= geom_bar()
w=geom_bar(aes(order=desc(cut)))
|
1
2
3
|
f = ggplot(df,aes,(x=x,y=y))
f + geom_line(linetype=2)
f + geom_line(linetype="dotdash")
|
포인트 그래프
1
|
p+geom_point(size=2.5) + geom_hline(yintercept=25,size=3.5)
|
1
|
p+geom_point(shape = 5)
|
1
|
p+geom_point(shape = 'k', size=3)
|
p+geom_point(shape = NA)
1
2
3
|
df2 = data.frame(x= 1:5, y=1:25, z=1:25)
s = ggplot(df2,aes(x,y))
s + geom_point(aes(shape=z),size=4) + scale_shape_identity()
|
1
2
3
4
|
dmod = lm(price~cut, data=diamonds)
cuts = data.frame(cut=unique(diamonds$cut),predict(dmod,data.frame(cut=unique(diamonds$cut)),se=TRUE)[c("fit","se.fit")])
se = ggplot(cuts, aes(x=cut,y=fit,ymin=fit-se.fit,ymax=fit+se.fit,colour=cut))
se + geom_pointrange()
|
1
2
|
p = ggplot(mtcars,aes(wt,mpg)) + geom_point()
p + annotate("rect",xmin=2,xmax=3.5, ymax=25,fill = "dark grey", alpha=.5)
|
1
2
|
p = qplot(disp, wt, data=mtcars) + geom_smooth()
p+scale_x_continuous(limit=c(325,500))
|
1
|
qplot(cut,price,data=diamonds, geom="boxplot")
|
-> 가로로 눕히려면 아래 코드 추가
last_plot() + coord_flip()
1
|
qplot(cut, data=diamonds, geom="bar")
|