• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    미해결

LDA 이미지 저장

20.05.20 20:23 작성 조회수 159

0

for (i in 8:12) {

                

                q_lda <- LDA(dtm, k=i) 

                q_topics <- tidy(q_lda, matrix="beta")

                q_top_terms <- q_topics %>%

                                group_by(topic) %>%

                                top_n(15, beta) %>%

                                ungroup() %>%

                                arrange(topic, -beta)

                q_top_terms$term<-repair_encoding(q_top_terms$term)

                tau<-tapply(q_top_terms$term,q_top_terms$topic,table)

         

                png(paste0("nate",i,".png"),width=500,height = 500)

                q_top_terms %>%

                                mutate(term=reorder(term, beta)) %>%

                                ggplot(aes(term, beta, fill=factor(topic))) +

                                geom_col(show.legend=FALSE) +

                                facet_wrap(~ topic, scales="free") +

                                coord_flip() +

                                theme(axis.text.y=element_text(family="HYGothic-Extra"))

                

                dev.off()

                

                key<-c(sapply(tau,names))

                key_list[[i]]<-key[!key %in% stw]

}

이렇게 코드를 돌리면, 파일은 생기는데, 이미지는 저장되지 않습니다. 왜 그런건가요?

답변 2

·

답변을 작성해보세요.

0

GKTJD님의 프로필

GKTJD

2020.06.01

알겠습니다! 감사합니다.

0

안녕하세요 gmlqls4732

ggplot 같은경우에는 for문 돌릴 때에 디렉토리에 자동 저장을 지원하지 않는 함수입니다.

그래서 저도 ggplot같은 경우에는 한장한장 이쁘게 만들어야 할 경우에만 사용하고, 그렇지 않은 경우에는

기본 plot함수를 사용하거나 다른 plot함수를 찾아서 사용합니다.