2022. 9. 21. 20:29ㆍ학부 강의/데이터마이닝
wordcloud
데이터를 시각화하는 패키지 중 하나다.
위와 같은 단어로 이뤄진 이미지를 만들 수 있다.
참고 : https://cran.r-project.org/web/packages/wordcloud/wordcloud.pdf
패키지 설치
install.packages("wordcloud")
패키지 로드
library(wordcloud)
새로 켜서 사용할 때마다 로드해주기.
wordcloud 실행
> data1<-readLines("vc.txt")
> data2<-table(data1)
table 함수는 '분할표'를 출력해주는 함수입니다. (단어의 수를 세어줌)
![]() |
![]() |
wordcloud(names(data2), freq=data2) # 빈도수는 data2에서 나타난 빈도수 그대로
- freq : 언급된 빈도수
??????????????
네?
wordcloud 폰트 깨짐 문제
폰트 깨짐 ㅅㄱ
맥북 m1으로 rstudio로 wordcloud를 실행할 경우 한글 폰트를 못 찾아서 생기는 오류다.
> wordcloud(names(data2),freq=data2, family="AppleGothic")
출처 : https://walkingfox.tistory.com/80
글자에 색상 넣기
> library(RColorBrewer)
> palete <- brewer.pal(9, "Set3")
> wordcloud(names(data2), freq=data2, scale=c(5,1), rot.per=0.25, min.freq=1, random.order = F, random.color=T, colors=palete, family="AppleGothic")
wordcloud() arguments
참고 : https://cran.r-project.org/web/packages/wordcloud/wordcloud.pdf
> library(RColorBrewer)
> palete <- brewer.pal(9, "Set3") # 팔레트 생성
> wordcloud(names(data2), background_color='white', max_words=50, freq=data2, scale=c(3,1), rot.per=0.25, min.freq=1, random.order = F, random.color=T, colors=palete, family="AppleGothic")
wordcloud2
wordcloud보다 더 예쁘고 사용하기 편하다.
https://cran.r-project.org/web/packages/wordcloud2/vignettes/wordcloud.html
Wordcloud2 introduction
This is an introduction to wordcloud2 package. This package provides an HTML5 interface to wordcloud for data visualization. Timdream’s wordcloud2.js is used in this package. This document show two main function in Wordcloud2: wordcloud2: provide traditi
cran.r-project.org
wordcloud2의 소개글을 보면…
This document show two main function in Wordcloud2
:
wordcloud2
: provide traditional wordcloud with HTML5letterCloud
: provide wordcloud with selected word(letters).
크게 두가지 기능을 제공하고 있다는 것을 알 수 있다.
install
install.packages("wordcloud2")
library(wordcloud2)
삐빅! 해당 방법으로 진행 시 버그가 발생합니다.
끝까지 보고서 올바른 방법으로 진행해주세요.
wordcloud2()
> library(wordcloud2)
> wordcloud2(data2)
위는 필수적인 사항이고 아래는 선택적인 사항이다.
출처 : https://cran.r-project.org/web/packages/wordcloud2/vignettes/wordcloud.html
예제 1
> wordcloud2(data2, color="random-light", backgroundColor = "grey")
궁서체는 아니야 ;;
> wordcloud2(data2, color="random-light", backgroundColor = "grey", fontFamily = "AppleGothic")
편안~
예제 2
> wordcloud2(data2, minRotation = 0.2, maxRotation = 0.8, minSize=10, rotateRatio = 1)
shape()
글자들을 특정한 모양으로 배치한다.
사용할 수 있는 모양은 아래와 같다.
- ‘circle’ (default)
- ‘cardioid’ (apple or heart shape curve, the most known polar equation)
- ‘diamond’ (alias of square)
- ‘triangle-forward’
- ‘triangle’
- ‘pentagon’
- ‘star’
> wordcloud2(data2, shape = 'star')
wordcloud2(data2, shape = 'circle', ellipticity = 0.5)
wordcloud2(data2, shape = 'circle', ellipticity = 1)
figPath()
wordcloud2(data2, figPath = "png.png", size = 1.5,color = "skyblue")
오류로 인하여 작동하지 않는 것을 볼 수 있다.
해결법은 letterCloud()에서도 동일하니 가장 마지막에 다루도록 한다.
letterCloud()
> letterCloud(data2, "O")
“O” 모양의 wordcloud를 생성한다.
> letterCloud(data2, "TRAVEL")
lettercloud 역시도 오류가 발생한다.
오류 해결
wordcloud2에서 글자나 그림만 검게 나오고 글자들이 보이지 않는 버그.
해결해보자.
1. install devtools
devtools이 필요하다.
devtools에 대한 설명은 아래 주소를 찾아가면 볼 수 있다.
출처 : https://www.r-project.org/nosvn/pandoc/devtools.html
https://www.r-project.org/nosvn/pandoc/devtools.html
The aim of devtools is to make your life as a package developer easier by providing R functions that simplify many common tasks. R packages are actually really simple, and with the right tools it should be easier to use the package structure than not. Pack
www.r-project.org
he aim of
devtools
is to make your life as a package developer easier by providing R functions that simplify many common tasks.
install.packages("devtools")
같이 설치되는 것들을 확인할 수 있다.
설치까진 한참 걸린다…. 한참 걸리면 그건 분명 문제가 있는 것이다.
어림도 없지 바로 새로운 오류가 발생한다! (오류의 오류라니!)
아마 devtools를 실행하는 것에 필요한 다른 dependencies 설치되지 않아서 발생한 문제인 것 같다.
dependencies까지 깔끔하게 설치하긴 위해서 우선 openssl부터 설치하는 것이 필요하다.
brew update
brew install openssl
다시!
install.packages("devtools")
안된다….
출처 : http://daplus.net/r-devtools-패키지-설치-문제/
출처 : https://johnmuschelli.com/neuroc/installing_devtools/index.html
다시 시도
구글링을 열심히 해본 결과 homebrew로 설치한 경우에 문제가 되는 경우가 많다고 한다.
그래서 cran version으로 다시 설치한다.
r : https://cran.r-project.org/bin/macosx/
rstudio : https://www.rstudio.com/products/rstudio/download/#download
# devtools 설치
> install.packages("devtools")
- Mac and Linux:
devtools::install_github("hadley/devtools")
- Windows:
library(devtools)
build_github_devtools()
#### Restart R before continuing ####
install.packages("devtools.zip", repos = NULL)
# Remove the package after installationunlink("devtools.zip")
여기서 울 뻔…
library(devtools)
devtools::install_github("lchiffon/wordcloud2")
안된다….
???
된다?
refresh를 연타했더니 된다….
와우 …
결론은...
1. homebrew 등 패키지 관리 시스템에서 다운로드하지 말고 웹 페이지에서 r과 rstudio를 설치한다.
2. install.packages("devtools")
install.packages("devtools")
3. devtools를 마저 설치한다.
- Mac and Linux:
devtools::install_github("hadley/devtools")
- Windows:
library(devtools)
build_github_devtools()
#### Restart R before continuing ####
install.packages("devtools.zip", repos = NULL)
# Remove the package after installationunlink("devtools.zip")
4. wordcloud2를 devtools를 통해서 github에서 설치한다.
library(devtools)
devtools::install_github("lchiffon/wordcloud2")
5. 명령어를 입력하고서 refresh를 연타한다.
library(devtools)
devtools::install_github("lchiffon/wordcloud2")
출처 : https://www.r-project.org/nosvn/pandoc/devtools.html
참고 : https://github.com/Lchiffon/wordcloud2/issues/12
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/012.gif)
'학부 강의 > 데이터마이닝' 카테고리의 다른 글
2022-10-14 데이터마이닝_6 (0) | 2022.10.14 |
---|---|
2022-10-06 데이터마이닝_5 (0) | 2022.10.06 |
2022-09-28 데이터마이닝_4 (0) | 2022.09.28 |
2022-09-20 데이터마이닝_2 (0) | 2022.09.20 |
2022-09-13 데이터마이닝_1 (0) | 2022.09.14 |