# 被启迪-R画出我的心

### 先来个正经的图

#### code

#导包
library(animation)
#注释一下，生成gif会使用到ImageMagick软件自己上网上找。
#如果出现convert: 455: unable to load moduleC:\ImageMagick\modules\coders\IM_MOD_RL_PNG_.dll‘
#请下载Microsoft Visual C++ 2008 Redistributable Package，还有就是环境变量的锅了。

#♥新型
t<-seq(0,2*pi,by=0.1)
x<-16*sin(t)^3
y<-13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)
a<-(x-min(x))/(max(x)-min(x))
b<-(y-min(y))/(max(y)-min(y))
#gif生成
saveGIF({
for (i in seq(1,length(a),3)){
sch<-a[1:i]
u<-b[1:i]
plot(sch,u)
}
text(0.2,0.6,"i love u")
text(0.8,0.1,"by sch")
}, movie.name = "bsh.gif")


### 来个不正经的图

#code
a1<-seq(0,2,0.01)
b1<-seq(0,1,0.01)
f<-function(a1,b1) ifelse(a1<=1, 11*a1*log10(a1)*b1*(b1-1)+exp(-((25*a1-25/exp(1))^2+(25*b1-25/2)^2)^3)/25, 11*(a1-1)*log10(a1-1)*b1*(b1-1)+exp(-((25*(a1-1)-25/exp(1))^2+(25*b1-25/2)^2)^3)/25)
c1<-outer(a1,b1,f)
persp(a1,b1,c1,theta=30,phi=30,expand=0.5,col="blue")


### 一部分去年的文本代码，就在这里保存一下。

library(plyr)
library(stringr)
library(jiebaR)
library(tm)
transword="感冒"
filenames=dir()
filenames00<- grep('\\.txt', filenames, value = TRUE)
txtinuse<-c()
j=1
for(filename in filenames00) {
path=paste0(getwd(),'/',filename)
txtinuse[j]=readChar(path,file.info(path)$size) j=j+1 } v=txtinuse v00=as.character(v) v01=v00 v00=gsub("\n","",v00) v00=gsub("\\x","",v00) #v00=gsub("x","",v00) v00=strsplit(v00,"。") #typeof(v00) #v00[2] v00<-as.vector(unlist(v00)) #str(v00) #typeof(v00) x=grep(transword,v00) #x v00=v00[x] #head(v00) removewords <- function(target_words,stop_words){ target_words = target_words[target_words%in%stop_words==FALSE] return(target_words) } engine <- worker() stopwords <- readLines("../mystopword.txt", encoding ='gbk') words <- removewords(segment(v00, engine), stopwords) wf <- as.data.frame(table(words)) wf <- wf[order(wf$Freq, decreasing = TRUE), ]

text_corpus <- Corpus(x = VectorSource(v00))
text_corpus <- tm_map(text_corpus, removeNumbers)
text_corpus<-tm_map(text_corpus, removePunctuation)
text_corpus<-tm_map(text_corpus, stripWhitespace)
#inspect(text_corpus)
#构建语料库
`

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120