R语言创作词云 word cloud generation

目录

  • 1. select packages

  • 2. clean text

  • 3. generate word cloud

  • 4. 一个小技巧 a little trick

1. Select packages

library("tm") #text mining
library("SnowballC")  #word stemming if necessary
library("wordcloud2") #word cloud generation
library("RColorBrewer") #color of word cloud
library("webshot") #save a word cloud as image
library("htmlwidgets")

2. clean text

因为我处理的是歌词文本,所以需要去除标点、数字和一些常见特殊符号(unicode $ @等)。需要注意的是像I’m I’d We’d 这样的词在去除标点的时候R是默认不作考虑。根据项目要求,我们把I’m 变成 I m来处理.
clean.text <- function(x)
{
   
  
  # remove rt
  ##x = gsub("rt", "", x)
  # remove at
  x = gsub("@\\w+", "", x)
  # remove punctuation
  x = gsub("[[:punct:]]", "", x)
  # remove numbers
  x = gsub("[[:digit:]]", "", x)
  # I'm to I m
  x = gsub("'", " "
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值