[英]Make three plot into one
有這樣的代碼:
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下面的三個合二為一呢?
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。 我該如何解決?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.