ACAIT

[R] 빅데이터 실무 분석 3차시_wordcloud(), RColorBrewer() 본문

전공 및 코드/R프로그래밍

[R] 빅데이터 실무 분석 3차시_wordcloud(), RColorBrewer()

831x99 2023. 6. 28. 12:54
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
### section 06_특정 키워드만 골라내서 분석하기
# 데이터베이스 머신에선 log 파일을 생성함.
# 동작 시간, 이벤트 등 모든 게 기록.
# 복사 붙여넣기 오류 unexpected -> 폰트 오류 가능성 높음. 
# 일일이 수정하거나 메모장 거쳐서 복붙.
 
setwd("c:\\temp\\R") 
# == c:/temp/R, c://temp//R
 
library(wordcloud)
library(RColorBrewer)
 
alert_1 = readLines("oracle_alert_testdb.log")
alert_2 = grep("^ORA-", alert_1, value = T)
alert_3 = substr(alert_2, 1, 9)
# 문자열 출력: grep(찾을 문자열, 기존 데이터, value = ?)
# value = F -> 인덱스 출력. (default)
# value = T -> 문자열 출력.
# 문자열 잘라내기: substr(기존 데이터, 시작 인덱스, 끝 인덱스)
 
 
errorcount = table(alert_3)
sort(errorcount, decreasing = T)[1:10]
# 집계: table(집계 대상)
# 정렬: sort(정렬 대상) (defalut 오름차순, decreasing = F)
# 내림차순 정렬: sort(정렬 대상, decreasing = T)
 
# 워드 클라우드 그리기
windows() # 시각화 띄울 팝업 창 생성
 
palete = brewer.pal(7, "Set1") 
# Set1에서 7개의 색 사용
 
wordcloud(
  names(errorcount), # 단어들
  freq = errorcount, # 언급량
  scale = c(5,0.5), # 단어 크기
  rot.per = 0.5, # 90도 회전 가로, 세로 단어 비율
  min.freq = 3, # 출력 최소 빈도 (cf. max.freq)
  random.order = F, # 랜덤 정렬 출력 -> F: 빈도 높은 것부터 중앙
  random.color = T, # 랜덤 색상 지정
  colors = palete)
cs