簡體   English   中英

將三個plot合二為一

[英]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。 我該如何解決?

當我運行您的命令時,對圖例稍作修改,幾分鍾后我得到以下 plot:

在此處輸入圖像描述 小修改:

legend("topright", bty="n", ...)

當我嘗試艾倫卡梅倫建議的變體時,我得到了以下信息:

par(mfrow=c(1,3), las=1, cex.axis=0.75, tck=-0.02, mgp=c(2,0.3,0))
plot(...) {...} # similar to your commands except no colour.

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM