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

lattice::panel.polygon and ReporteRs::addPlot #221

Open tyner opened 6 years ago

tyner commented 6 years ago

Hi,

If I run

library(lattice)
library(ReporteRs)

p <- xyplot(1 ~ 1,
            xlim = c(0, 1),
            ylim = c(0, 1),
            panel = function(x, y, ...) {
                eps <- 0.0001

                panel.polygon(x = c(0.25, 0.75, 0.75, 0.25),
                              y = c(-eps, -eps, 0.50, 0.50),
                              border = NA,
                              col = "yellow"
                              )
            }
            )

out <- ReporteRs::pptx(title = "foo")
out <- ReporteRs::addSlide(doc = out,
                           slide.layout = "Content with Caption"
                           )
out <- ReporteRs::addPlot(doc = out,
                          fun = print,
                          x = p
                          )
ReporteRs::writeDoc(doc = out, file = "~/polygon.pptx")

then it renders the yellow rectangle as a triangle. This happens on both linux as well as on windows. Here is my sessionInfo()

R version 3.4.3 (2017-11-30) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 16.04.3 LTS

Matrix products: default BLAS: /usr/lib/libblas/libblas.so.3.6.0 LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8
[9] LC_ADDRESS=en_US.UTF-8 LC_TELEPHONE=en_US.UTF-8
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8

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

other attached packages: [1] gdtools_0.1.4 ReporteRs_0.8.8.9000 ReporteRsjars_0.0.2 [4] lattice_0.20-35

loaded via a namespace (and not attached): [1] Rcpp_0.12.10 knitr_1.15.1 xml2_1.1.1 bindr_0.1
[5] magrittr_1.5 munsell_0.4.3 xtable_1.8-2 colorspace_1.3-2 [9] R6_2.2.0 rlang_0.1.4 plyr_1.8.4 dplyr_0.7.4
[13] tools_3.4.3 grid_3.4.3 gtable_0.2.0 png_0.1-7
[17] rvg_0.1.3 R.oo_1.21.0 htmltools_0.3.5 lazyeval_0.2.0
[21] digest_0.6.12 assertthat_0.2.0 tibble_1.3.4 bindrcpp_0.2
[25] shiny_1.0.2 rJava_0.9-8 purrr_0.2.2 officer_0.1.1
[29] ggplot2_2.2.1 base64enc_0.1-3 R.utils_2.5.0 mime_0.5
[33] glue_1.2.0 compiler_3.4.3 scales_0.4.1 R.methodsS3_1.7.1 [37] httpuv_1.3.3 pkgconfig_2.0.1

Any ideas? I realize that part of the rectangle is outside of the grid viewport, but figured I would ask here first since it does the right in in other graphics devices.

Regards, Ben

davidgohel commented 6 years ago

Hi, that's a clipping issue (in package rvg). Same problem can be found with officer:

library(lattice)
library(officer)
library(rvg)

p <- xyplot(1 ~ 1,
            xlim = c(0, 1),
            ylim = c(0, 1),
            panel = function(x, y, ...) {
              eps <- 0.0001

              panel.polygon(x = c(0.25, 0.75, 0.75, 0.25),
                            #y = c(0, -eps, 0.50, 0.50), # This is working
                            y = c(-eps, -eps, 0.50, 0.50), # This is not working
                            border = NA,
                            col = "yellow"
              )
            }
)

out <- read_pptx()
out <- add_slide(out,
                 layout = "Title and Content", master = "Office Theme")
out <- ph_with_vg(out, code = print(p), type = "body")

print(out, target = "polygon.pptx")

Sorry, I don't have time to work on that now, it's unlikely to be solved soon.