bnosac / textplot

Text Plots
GNU General Public License v2.0
54 stars 8 forks source link

Simplified Chinese is not working in the BTM plot (bigram plot) #4

Closed DQKF closed 3 years ago

DQKF commented 3 years ago

I have some problems with the font issues as I use R Package BTM. As one may see in the graph as attached, "Simplified Chinese" is not working as plotted.

Here's the plot code: M02<-plot(model02, top_n = 10, family = "SimSun", title = "BTM model", subtitle = "R packages in the NLP/Machine Learning task views", labels = c("Topic01", "Topic02", "Topic03", "Topic04", "Topic05", "Topic06", "Topic07", "Topoc08", "Topic09", "Topic10", "Topic11", "Topic12", "Topic13", "Topic14", "Topic15"))

Text mining in Simplified Chinese.

螢幕快照 2021-02-22 00 18 15

XJP_neg_BTM

jwijffels commented 3 years ago

Hello @DQKF Can you share your model02object such that I can reproduce this locally save(model02, file = "model02.RData") or provide a reproducible example with some simplified chinese terms in there showing this behaviour.

jwijffels commented 3 years ago

I'm not sure what the cause of this is. This is what I'm getting when applying on your model object: Rplot

I'm running this on Windows. And got a similar plot on a Ubuntu system. Maybe you are on another system?

library(BTM)
library(textplot)
library(ggraph)
library(ggforce)
library(concaveman)
library(ggplot2)
library(igraph)
load("C:/Users/Jan/Desktop/model02.RData")
plot(model02, biterms = model02$biterms$biterms, top_n = 10, family = "SimSun")
Sys.getlocale()
[1] "LC_COLLATE=Dutch_Netherlands.1252;LC_CTYPE=Dutch_Netherlands.1252;LC_MONETARY=Dutch_Netherlands.1252;LC_NUMERIC=C;LC_TIME=Dutch_Netherlands.1252"
DQKF commented 3 years ago

I am running all the jobs on the Apple IOS system, pretty weird! Thanks anyway!

jwijffels commented 3 years ago

This plotting functionality relies on the ggraph package and the ggplot2 package. Maybe this is the solution to your question: https://community.rstudio.com/t/chinese-characters-in-ggplot-on-macos/4429

jwijffels commented 3 years ago

Maybe you need to set this upfront:

library(BTM)
library(textplot)
library(ggraph)
library(ggforce)
library(concaveman)
library(ggplot2)
library(igraph)
load("C:/Users/Jan/Desktop/model02.RData")

theme <- theme_get()
theme$text$family <- "STFangsong"
theme_set(theme)

plot(model02, biterms = model02$biterms$biterms, top_n = 10)
DQKF commented 3 years ago

I just add > showtext_auto(), and everything's fine with the graph! Thanks, Dr. Wijffels! show-text-auto

jwijffels commented 3 years ago

Ok great. Good to know.