Сделайте три сюжета в один - PullRequest
0 голосов
/ 20 июня 2020

Имея такой код:

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. Как исправить?

1 Ответ

0 голосов
/ 20 июня 2020

Когда я запускаю ваши команды с незначительным изменением легенды, через несколько минут я получаю следующий график:

enter image description here Незначительное изменение:

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.

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...