davidgohel / ReporteRs

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

addPlot - raster rendering fails on ggplot2 plots with continuous colour mapping #95

Closed rcst closed 8 years ago

rcst commented 9 years ago

Hi David,

I also would like to thank you for having created such a nice package, I enjoy working with it alot.

I found that addPlot.pptx(..., vector.graphic = TRUE) has a problem when printing a ggplot2 plot-object with continuous colour mapping. See example below:

library(ReporteRs)
library(ggplot2)
library(data.table)

# This is a reproducible example for reporting a bug
# The function vector.pptx.graphic produces a warning
# when a ggplot a scatter plot with a continuous colour scale is passed vector.graphic = TRUE
# the warning states that raster rending is not implemented on this device and
# the resulting plot is missing legend entries and is not a vector graphic:
# In grid.Call.graphics(L_raster, x$raster, x$x, x$y, x$width, x$height,  :
# Rasterrendering ist für dieses Gerät nicht implementiert
# it seems that the problem is with continuous colour scales
# if I remove the coulor mapping from the plot, it works as expected

dt <- data.table(t = seq(0, 10, 0.1), y = rnorm(101), z = seq(0, 10, 0.1))

p <- ggplot(data = dt2, mapping = aes(x = t, y = y, colour = z)) +
    geom_line()

mydoc <- pptx(title = "Test PPT")
mydoc <- addSlide(doc = mydoc, "Title and Content")
mydoc <- addPlot(doc = mydoc, fun = print, x = p, vector.graphic = TRUE)
writeDoc(doc = mydoc,  "TestPPT.pptx")

The resulting graphic in the pptx-file looks like this: bild1

... which in PowerPoint is not editable and the colour scale is missing in the legend.

Here is the output of sessionInfo():

> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

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

other attached packages:
 [1] plyr_1.8.3          intervals_0.15.1    arulesViz_1.0-2     arules_1.1-9        Matrix_1.2-1        data.table_1.9.4    ggplot2_1.0.1      
 [8] ReporteRs_0.8.2     ReporteRsjars_0.0.2 vimcom_1.2-6       

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.6          bitops_1.0-6         iterators_1.0.7      tools_3.2.1          digest_0.6.8         gtable_0.1.2         lattice_0.20-31     
 [8] foreach_1.4.2        registry_0.3         seriation_1.1-2      proto_0.3-10         TSP_1.1-3            rJava_0.9-7          stringr_1.0.0       
[15] cluster_2.0.1        gtools_3.5.0         caTools_1.17.1       lmtest_0.9-34        vcd_1.4-1            scatterplot3d_0.3-36 gdata_2.17.0        
[22] reshape2_1.4.1       magrittr_1.5         scales_0.2.5         gplots_2.17.0        codetools_0.2-11     gclus_1.3.1          MASS_7.3-40         
[29] colorspace_1.2-6     labeling_0.3         KernSmooth_2.23-14   stringi_0.5-5        munsell_0.4.2        chron_2.3-47         zoo_1.7-12

Do you know what's the issue with it, or am I mistaking something?

davidgohel commented 9 years ago

Hi,

Yes, this is a known issue. This package should solve it: https://github.com/davidgohel/gdtools

However, there is an issue with the Windows version (and don't have a Windows computer actually). I think next week I will be able to work on solving this issue with a Win PC.

David

rcst commented 9 years ago

Hi David,

I'm using a windows machine, so I guess that's why I'm still getting this warning when having installed gdtools, resulting in the same plot missing the gradient colour bar legend.

Eric

davidgohel commented 9 years ago

Sorry, I was not clear. The new package should solve the issue but this new package is not integrated yet and has an issue with Windows.

David

davidgohel commented 8 years ago

Hi,

This is solved (with packages rvg and gdtools)

David

rcst commented 8 years ago

Thank you so much!

aipsa commented 8 years ago

Hi David and Eric, Trying to use addPlot.pptx(..., vector.graphic = TRUE) function with a scale_fill_gradient in my ggplot I have the same problem so I'm very interested to know how does it work for you?

`library(ReporteRs) library(ggplot2) library(dplyr) library(reshape2)

p <- ggplot(melt(data.frame(mtcars2)) %>% group_by(variable) %>% mutate(mean = mean(value)), aes(x = variable, y = value)) + geom_boxplot(aes(fill=mean)) + scale_fill_gradient(low=hcl(0,100,75), high=hcl(195,100,75))+ theme(text = element_text(size=16), axis.text.x = element_text(face="bold", angle = 90, hjust = 1), axis.text=element_text(size=20),legend.text=element_text(size=16),legend.title = element_text(size=16, face="bold"))+ xlab("variable")

mydoc <- pptx(title = "Test PPT") mydoc <- addSlide(doc = mydoc, "Title and Content") mydoc <- addPlot(doc = mydoc, fun = print, x = p, vector.graphic = TRUE) writeDoc(doc = mydoc, "TestPPT.pptx") `

Warning message: In grid.Call.graphics(L_raster, x$raster, x$x, x$y, x$width, x$height, : raster rendering is not implemented for this device

PS : I'm using a windows machine.

Thanks

Ali

davidgohel commented 8 years ago

Hi Ali,

I think you are not using the github version. This new version support raster rendering.

David