被启迪-R画出我的心

先来个正经的图

love heart

code
#导包
library(animation)
#注释一下,生成gif会使用到ImageMagick软件自己上网上找。
#如果出现convert: 455: unable to load module`C:\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)
#构建语料库
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值