我正面临以下问题。 我有12个文本,我需要为其创建一个色散图。我希望R一起显示几个色散图。现在,我拥有了所需的所有信息,并且能够创建单独的色散图。正如这里(https://www.statmethods.net/advgraphs/layout.html)所述,我只是不知道如何将它们全部绘制在一起。这是我的代码:
input.dir<-"corpus"
files.v<-dir(input.dir, "\\.txt$")
make.file.word.v.l<-function(files.v, input.dir){
text.word.vector.l<-list()
for(i in 1:length(files.v)){
text.v <- scan(paste(input.dir, files.v[i], sep="/"), what="character", sep="\n")
Encoding(text.v)<-"UTF-8"
text.v <- paste(text.v, collapse=" ")
text.lower.v <- tolower(text.v)
text.words.v <- strsplit(text.lower.v, "\\W")
text.words.v <- unlist(text.words.v)
text.words.v <- text.words.v[which(text.words.v!="")]
text.word.vector.l[[files.v[i]]] <- text.words.v
}
return(text.word.vector.l)
}
corpus.l<-make.file.word.v.l(files.v, input.dir)
此列表包含所有文本。
其中包含所有“时间”:
tiempo <- function(corpus.l){
tiempo.l<-list()
for (i in 1:length(corpus.l)){
time<-seq(1:length(corpus.l[[i]]))
tiempo.l[[files.v[i]]]<-time
}
return(tiempo.l)
}
tiempo.l<-tiempo(corpus.l)
hits<-function(keyword){
hits.l<-list()
for (i in 1:length(corpus.l)) {
hits.v<-which(corpus.l[[i]]==keyword)
hits.keyword.v<-rep(NA, length(tiempo.l[[i]]))
hits.keyword.v[hits.v]<-1
hits.l[[files.v[i]]]<-hits.keyword.v
}
return(hits.l)
}
noches.todos<-hits("noches")
plot(noches.todos[[1]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
我有12本书,我想同时绘制所有12个散布图,以便可以对其进行比较。我相信这是可能的,我只是不知道该怎么做。
答案 0 :(得分:0)
我找到了答案。您所需要做的就是设置par:
par(mfrow =c(4,3))
options(scipen=5)
plot(noches.todos[[1]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[2]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[3]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[4]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[5]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[6]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[7]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[8]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[9]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[10]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[11]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
plot(noches.todos[[12]], main="Dispersion plot",
xlab="time", ylab="keyword", type="h", ylim=c(0,1), yaxt='n')
您还可以使用选项(密码)来避免科学计数法。 我无法在所有列中的单个列中绘制R图,但是我能够获得良好的图像。行的图形显示可能会有限制。 mfrow中的第一个数字(在我的情况下为4)设置行数,第二个数字(在我的情况下为3)设置列数。这意味着每行将获得3个图,即12个图形。