Имея такой код:
library(stm)
gadarian <- gadarian
K<-c(5,10,15)
temp<-textProcessor(documents=gadarian$open.ended.response,metadata=gadarian)
out <- prepDocuments(temp$documents, temp$vocab, temp$meta)
documents <- out$documents
vocab <- out$vocab
meta <- out$meta
set.seed(02138)
K<-c(5,10,15)
df1 <- searchK(documents, vocab, K, prevalence=~treatment + s(pid_rep), data=meta)
df2 <- searchK(documents, vocab, K, prevalence=~treatment + s(pid_rep), data=meta)
df3 <- searchK(documents, vocab, K, prevalence=~treatment + s(pid_rep), data=meta)
Как можно объединить три следующих графика в один?
plot(df1$results$K,df1$results$semcoh, type = "b",
xlab = "Number of Topics (K)", ylab = "Semantic Coherence",
main="Semantic Coherence")
plot(df2$results$K,df2$results$semcoh, type = "b",
xlab = "Number of Topics (K)", ylab = "Semantic Coherence",
main="Semantic Coherence")
plot(df3$results$K,df3$results$semcoh, type = "b",
xlab = "Number of Topics (K)", ylab = "Semantic Coherence",
main="Semantic Coherence")
Я пробовал вот это:
plot(df1$results$K,df1$results$semcoh,
ylim=range(c(df1$results$semcoh,df2$results$semcoh)),
xlim=range(c(df1$results$K,df2$results$K)), type="b",col="red",
xlab = "Number of Topics (K)", ylab = "Semantic Coherence",
main="Semantic Coherence")
lines(df2$results$K,df2$results$semcoh,col="green", type="b")
lines(df3$results$K,df3$results$semcoh,col="blue", type="b")
# Add a legend
legend(5, -5.52, legend=c("score_1", "score_2", "score_3"),
col=c("red", "green", "blue"), lty=1, cex=0.8, pch = 1)
, но проблема в том, что отображается последняя синяя линия.
Только из df3. Как исправить?