Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factoextra and japanese text #31

Closed
kassambara opened this issue Apr 13, 2017 · 12 comments
Closed

factoextra and japanese text #31

kassambara opened this issue Apr 13, 2017 · 12 comments

Comments

@kassambara
Copy link
Owner

kassambara commented Apr 13, 2017

(email from a user)
I am using Mac and RStudio/R.

When I use ggplot on my Mac, I have to set the font family to "sans"
(in .Rprofile I set up the "sans" to Japanese fonts)

Like this.

p <- ggplot(data, aes(x=Dim1,y=Dim2)) + theme_grey(base_family="sans")

So with  fviz_ca_biplot, I tried same way, but font did not selected.


library(FactoMineR)
library(factoextra)

.tbl2.1 <- matrix(c(395, 2456,1758,
                 147, 153, 916, 
                 694, 327, 1347),byrow=T,3,3)
dimnames(.tbl2.1) <- list(地域=c("オスロ","中部地域","北部地域"),
                       犯罪=c("強盗", "詐欺","破壊") )
.tbl2.1
res.CA <- CA(.tbl2.1,graph=FALSE)
p <- fviz_ca_biplot(res.CA,map="simbiplot",title="simbiplot")
p + theme_grey(base_family="sans")

Please advice me how I can select the Font for fviz_ca.

@kassambara
Copy link
Owner Author

factoextra depends on ggpubr to create scatter plots.

Please, install the latest developmental version of factoextra and ggpur as follow:

if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/ggpubr")
devtools::install_github("kassambara/factoextra")

Then, try this:

library(FactoMineR)
library(factoextra)

.tbl2.1 <- matrix(c(395, 2456,1758,
                    147, 153, 916, 
                    694, 327, 1347),byrow=T,3,3)
dimnames(.tbl2.1) <- list(地域=c("オスロ","中部地域","北部地域"),
                            犯罪=c("強盗", "詐欺","破壊") )


res.CA <- CA(.tbl2.1,graph=FALSE)

fviz_ca_biplot(res.CA,map="simbiplot",title="simbiplot",
               font.family = "HiraKakuProN-W3")

rplot

@419kfj
Copy link

419kfj commented Apr 14, 2017

Thank you for your advice, I could use Japanese Font correctly.
For "title" also, I could use Japanese.

(** May be this my RStudio setting issue, the graph out put to plot window, Japanese still □ . In the PDF output by knitr, I can see Japanse FONT, and by Export form plot window, it also good. If anyone have some advice, I will be happy ;-))

kazuo

@kassambara
Copy link
Owner Author

Great that it works!

Concerning the problem with RStudio plot window, these forums might help:

kassambara added a commit that referenced this issue Apr 14, 2017
@419kfj
Copy link

419kfj commented Apr 23, 2017

kassambara,

#Thank you for your support.
FONT issue, again.
I can use japanse font in scatter plot area.
But as I wrote above, when I use Japanse in title=".....", I have to add following line. Is it spec ?

fviz_ca_biplot(res.CA,map="simbiplot",title="対称biplot", font.family = "HiraKakuProN-W3")

title is not displayed.

fviz_ca_biplot(res.CA,map="simbiplot",title="対称biplot", font.family = "HiraKakuProN-W3") + theme(text = element_text(family = "HiraKakuProN-W3"))
It works.

reagrds.

@kassambara
Copy link
Owner Author

Thank you for pointing this out. I updated now the ggpubr package (which is used by factoextra for drawing scatter plot).

It should work now.

Please install the latest developmental version of ggpubr before testing:

if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/ggpubr")

Kind regards

@419kfj
Copy link

419kfj commented Apr 24, 2017 via email

@419kfj
Copy link

419kfj commented May 11, 2017

KASSAMBARA,

I found another problem on FONT.

I made poisonJ data, with converted variable name and category into Japanese.
(please doenload from this URL. I put CSV file http://419kfj.sakura.ne.jp/db/wp-content/uploads/2017/05/poison.csv)

And on the way translating this page http://www.sthda.com/english/wiki/multiple-correspondence-analysis-essentials-interpretation-and-application-to-investigate-the-associations-between-categories-of-multiple-qualitative-variables-r-software-and-data-mining
into Japanese.

Then I checked fviz_ functions which are used in above document.

Then I encountered the Font problem when I use "fviz_cpntrib" ,"fviz_cos2", and with habillage option on "fviz_mca_biplot".

graph

For every cases, I have to add the "+ theme(text = element_text(family = "HiraKakuProN-W3")) ".

<fviz_contrib(res.mca, choice = "ind", axes = 1:2, top = 20, font.family = "HiraKakuProN-W3") + theme(text = element_text(family = "HiraKakuProN-W3"))

Is it the same issue as "Japanse title" which I asked you before ?

And when I translated your "multiple-correspondence-analysis-essentials....", I have to insert same option "font.family = "HiraKakuProN-W3" for every command line. I would be very happy if I can setup this one in a .Rprofile or another setting command. Because in a one report I need same setting from the begining to the end.

regards.

kazuo

@419kfj
Copy link

419kfj commented May 11, 2017

Another problem.

when I use fviz_mca_var( ) with supplyment variable included res.mca. I tried to put both "ont.family = "HiraKakuProN-W3"" and "+ theme(text = element_text(family = "HiraKakuProN-W3"))", there are no effect on it.

I attached the graph with script. I use "sans" for my setting. Please read it as "HiraKakuProN-W3".

graph2

@kassambara
Copy link
Owner Author

Ok thanks, i'll update these functions as soon as possible

kassambara added a commit that referenced this issue May 23, 2017
@kassambara
Copy link
Owner Author

fixed now, thanks!

Install the latest developmental version and try this:

d <- read.csv("http://419kfj.sakura.ne.jp/db/wp-content/uploads/2017/05/poison.csv")
res.mca <- MCA(d, ind.sup=53:55, quanti.sup = 1:2, quali.sup = 3:4,  graph=FALSE)

my_theme <- theme_minimal(base_family = "HiraKakuProN-W3")
fviz_contrib(res.mca, "var", ggtheme = my_theme)


fviz_mca_var(res.mca, font.family = "HiraKakuProN-W3", invisible = "var" )

@419kfj
Copy link

419kfj commented May 24, 2017

I check both of above with factoextra 1.0.4.999.

These function works well ;-)

Thank you for your support and nice packege !

kazuo

@kassambara
Copy link
Owner Author

Ok, great! so we can close this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants