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

Font type and size not changing: #223

Closed fnamugera closed 6 years ago

fnamugera commented 6 years ago

Hi ,

I have followed up a number of questions on the above question and i have tried them out but my font size is still very small on the plot (axis text and other texts within the plot).

Below is a sample of my code:

options("ReporteRs-fontsize"= 14, "ReporteRs-default-font"="Times New Roman")
doc_path <-"E:/LG/Innovations/FP/2018/Reports/monthly report/templete.pptx"
doc<- pptx(template=doc_path)

myplot<- which_plot[which_plot$Number>14,]%>%
  ggplot(aes(x =reorder(reason_not, -Number), y = Number)) + geom_bar(aes(y = Number),stat = 'identity', position = 'dodge', width = .5, fill= "blue")+
  geom_text(aes(label = paste0(Freq,"%")), stat = 'identity',position = position_dodge(width = .4) ,hjust = -.1, size = 3.4) + theme_bw() + theme(panel.grid = element_blank())+
  xlab("Number of clients") +   theme(axis.text = element_text(size = 10, colour = "grey40", face = "bold"), axis.title.y = element_blank())+
  coord_flip() + theme(axis.ticks = element_blank())

doc<- addSlide(doc = doc, "Title and Content")
doc<- addTitle(doc, "short term followups - COmmonly reported side effects from Sayana:", sum(which_plot$Number) )
plotFunc<- function(){}
doc<- addPlot(doc, x = myplot, fun = print)

My sessions is:


> sessionInfo() R version 3.4.3 (2017-11-30) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)  Matrix products: default  locale: [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                           [5] LC_TIME=English_United States.1252      attached base packages: [1] stats     graphics  grDevices utils     datasets  methods   base       other attached packages: [1] dplyr_0.7.4          ggplot2_2.2.1        XLConnect_0.2-13     XLConnectJars_0.2-13 RPostgreSQL_0.6-2    [6] DBI_0.7               loaded via a namespace (and not attached):  [1] Rcpp_0.12.14     assertthat_0.2.0 R6_2.2.2         grid_3.4.3       plyr_1.8.4       gtable_0.2.0      [7] magrittr_1.5     scales_0.5.0     pillar_1.0.1     rlang_0.1.6      lazyeval_0.2.1   bindrcpp_0.2     [13] labeling_0.3     tools_3.4.3      glue_1.2.0       munsell_0.4.3    yaml_2.1.15      compiler_3.4.3   [19] pkgconfig_2.0.1  colorspace_1.3-2 rJava_0.9-9      bindr_0.1        tibble_1.4.1
--

>
davidgohel commented 6 years ago

Hi

Please, follow the guidelines:

  1. reproducible example. I can't reproduce your example.
  2. sessionInfo()

It had to be executed after you loaded the packages used by your example. This will let me know what is your version of R and what are the versions of the packages you used in your example.

etc.

fnamugera commented 6 years ago

Thanks David,

Here is the information: am working on a big report hence the many packages.

options("ReporteRs-fontsize"= 14, "ReporteRs-default-font"="Times New Roman")
doc_path <-"C:/Users/Frank_2/Desktop/Presentation1.pptx"
doc2<- pptx(template=doc_path)

myplot<-   ggplot(iris, aes(x =Species, y = "Petal.Width")) + geom_bar(stat = 'identity', position = 'dodge', width = .5, fill= "blue")

doc2<- addSlide(doc = doc2, "Title and Content")
doc2<- addTitle(doc2, "Using Iris dataset" )
plotFunc<- function(){}
doc<- addPlot(doc2, x = myplot, fun = print)
writeDoc(doc2, doc_path)

My sessions:

 sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] bindrcpp_0.2         gdtools_0.1.6        DiagrammeR_0.9.2     plotrix_3.7          ReporteRs_0.8.9     
 [6] ReporteRsjars_0.0.3  lubridate_1.7.1      stringr_1.2.0        scales_0.5.0         dplyr_0.7.4         
[11] plyr_1.8.4           reshape2_1.4.2       outliers_0.14        ggplot2_2.2.1        XLConnect_0.2-13    
[16] XLConnectJars_0.2-13 rJava_0.9-9          RPostgreSQL_0.6-2    DBI_0.7             

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.14       tidyr_0.7.2        visNetwork_2.0.3   png_0.1-7          assertthat_0.2.0  
 [6] digest_0.6.12      mime_0.5           R6_2.2.2           pillar_1.0.1       rlang_0.1.6       
[11] lazyeval_0.2.1     uuid_0.1-2         rstudioapi_0.7     R.utils_2.6.0      R.oo_1.21.0       
[16] labeling_0.3       downloader_0.4     readr_1.1.1        htmlwidgets_1.0    igraph_1.1.2      
[21] munsell_0.4.3      shiny_1.0.5        compiler_3.4.3     influenceR_0.1.0   rgexf_0.15.3      
[26] httpuv_1.3.5       pkgconfig_2.0.1    base64enc_0.1-3    rvg_0.1.7          htmltools_0.3.6   
[31] tibble_1.4.1       gridExtra_2.3      XML_3.98-1.9       viridisLite_0.2.0  R.methodsS3_1.7.1 
[36] grid_3.4.3         jsonlite_1.5       xtable_1.8-2       gtable_0.2.0       magrittr_1.5      
[41] zip_1.0.0          stringi_1.1.6      viridis_0.4.1      xml2_1.1.1         brew_1.0-6        
[46] RColorBrewer_1.1-2 tools_3.4.3        glue_1.2.0         officer_0.2.1      purrr_0.2.4       
[51] hms_0.4.0          Rook_1.1-1         yaml_2.1.15        colorspace_1.3-2   knitr_1.17        
[56] bindr_0.1 

Thanks

davidgohel commented 6 years ago

Thanks,

There is no issue here. You are using ggplot, you need to use ggplot syntax. The corresponding fonts are specified in addPlot (see my example):

library(ReporteRs)
library(ggplot2)

options("ReporteRs-fontsize"= 14, "ReporteRs-default-font"="Times New Roman")
doc_path <-"Presentation1.pptx"
doc2<- pptx()

myplot <- ggplot(iris, aes(x =Species, y = "Petal.Width")) + 
  geom_bar(stat = 'identity', position = 'dodge', width = .5, fill= "blue")
myplot <- myplot + 
  theme(text = element_text(size = 30, family = "serif", colour = "orange"))# this set for all text family serif and size = 30

doc2<- addSlide(doc = doc2, "Title and Content")
doc2<- addTitle(doc2, "Using Iris dataset" )
plotFunc<- function(){}
doc<- addPlot(doc2, x = myplot, fun = print, 
              fontname_serif = "Times New Roman", # default args, see ?addPlot
              fontname_sans = "Calibri",# default args, see ?addPlot, by default ggplot use family = "sans"
              fontname_mono = "Courier New")
writeDoc(doc2, doc_path)

Can you close the issue if it answer your question? I don't think there is any bug here.

fnamugera commented 6 years ago

Thanks Much David... Indeed it's solved now.