davidgohel / ReporteRs

Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer.
245 stars 44 forks source link

ctree model plot changes from EN to greek letters #82

Closed jpmorris closed 9 years ago

jpmorris commented 9 years ago

7-6-2015 3-18-50 pm I'm trying to output a ctree (partykit package) plot with:

myppt = addPlot(myppt, fun = function(){
  plot(model.ctree, vector.graphics=F)
})

It plots with the right words in Rstudio, but whenit outputs to the ppx, it suddenly turns to greek at one point in the plot. My environment is:

> l10n_info()
$MBCS
[1] FALSE

$`UTF-8`
[1] FALSE

$`Latin-1`
[1] TRUE

$codepage
[1] 1252

Which I think is the correct encoding. Either way, trying to set based on other Issue reports I get:

> system('defaults write org.R-project.R force.LANG en_US.UTF-8')
Warning message:
running command 'defaults write org.R-project.R force.LANG en_US.UTF-8' had status 127 
davidgohel commented 9 years ago

Hi,

The vector.graphics argument need to be set in the addPlot function, not the plot function.

myppt = addPlot(myppt, vector.graphics=F, fun = function(){
    plot(model.ctree)
})

This will solve your issue by switching the graphical device to png and not to ReporteRs' one (where code need to be improved to handle UTF-8 when running within R for Windows).

David

jpmorris commented 9 years ago

vector.graphics = F seems to crash my rstudio session (using your code above for these ctrees)

davidgohel commented 9 years ago

I can't reproduce the problem. I ran:

library("partykit")
ls <- data.frame(y = gl(3, 50, labels = c("A", "B", "C")),
   x1 = rnorm(150) + rep(c(1, 0, 0), c(50, 50, 50)),
   x2 = runif(150))
ct <- ctree(y ~ x1 + x2, data = ls)

library( ReporteRs )
myppt = pptx()
myppt = addSlide( myppt, "Title and Content")

myppt = addPlot(myppt, vector.graphic = T, fun = function(){
  plot(ct)
})
myppt = addSlide( myppt, "Title and Content")

myppt = addPlot(myppt, vector.graphic = F, fun = function(){
  plot(ct)
})

writeDoc( myppt, "jpmorris.pptx")

Below a screenshot of the resulting file:

capture d ecran 2015-07-07 a 18 27 55
jpmorris commented 9 years ago

Hmmm. Doesn't work for me with my pared down example:

Sys.setenv(JAVA_HOME="C:\\Users\\mor20\\progs\\jre1.8.0_45")
library( ReporteRs )
library(dplyr)
library(partykit)

myppt = pptx(template = "PowerPoint Template.pptx")

myppt = addSlide(myppt, "Title and Content")
myppt = addTitle(myppt, "test")
#
#
current.trans.2005.etm <- currentTransactions_2005 %>%      
select(GENERATION_TXT, SERVICE_RANGE_TXT, GENDER_TXT, ANNUAL_SALARY_AMT,   ETHNICITY_TXT, MY.termtype) %>%
mutate(MY.termpred = factor(ifelse(MY.termtype %in% c("Involuntary", "Other", "Voluntary", "Retirement"), "non-Active", "Active")))
model.ctree = ctree(MY.termpred ~ GENERATION_TXT + SERVICE_RANGE_TXT + GENDER_TXT + ANNUAL_SALARY_AMT + ETHNICITY_TXT, data=current.trans.2005.etm)
myppt = addPlot(myppt, vector.graphics = F, fun = function(){
  plot(model.ctree)
})

writeDoc( myppt, "C:/Users/mor20/Downloads/pp_simple_example.pptx" )

I guess it could be my environment (java I'm using), template, or dataset?

7-7-2015 11-43-31 am

jpmorris commented 9 years ago

Ok, after modifying your example with my template, dplyr data.frame, java version I found the problem, I was using "vector.graphics" not "vector.graphic" (notice trailing 's'). This causes rstudio to crash for me. Thanks for your help.

davidgohel commented 9 years ago

Hi,

a quick comment,

If your JRE is correctly installed, you don't need

Sys.setenv(JAVA_HOME="C:\\Users\\mor20\\progs\\jre1.8.0_45")
jpmorris commented 9 years ago

Because I don't have admin access to this machine, and because I get Java 32/64 bit confilct with a particular website, this is the easiest solution I've found that doesn't break a different webpage I use on a regular basis.