ropensci / magick

Magic, madness, heaven, sin
https://docs.ropensci.org/magick
Other
461 stars 66 forks source link

image_graph() res argument not accepting inputs #246

Closed xgirouxb closed 4 years ago

xgirouxb commented 4 years ago

Hello, I'm trying to print many ggplot images to a specific resolution so that I can control the output dimensions of the plots. However, its seems that the res argument within the image_graph() function does not respond to inputs and reverts to the default 72 dpi:

# Load libraries
library(ggplot2)
library(magick)
#> Linking to ImageMagick 6.9.7.4
#> Enabled features: fontconfig, freetype, fftw, lcms, pango, x11
#> Disabled features: cairo, ghostscript, rsvg, webp

# Create ggplot
data(iris)
iris_plot <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point()

# Convert ggplot to magick image
magick_image <- image_graph(res = 300)
print(iris_plot)
dev.off()
#> png 
#>   2

# Check output image resolution
image_info(magick_image)$density
#> [1] "72x72"

Created on 2020-05-05 by the reprex package (v0.3.0)

Session info ``` r sessionInfo() #> R version 3.6.3 (2020-02-29) #> Platform: x86_64-pc-linux-gnu (64-bit) #> Running under: Linux Mint 19.2 #> #> Matrix products: default #> BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 #> LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so #> #> locale: #> [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C #> [3] LC_TIME=en_CA.UTF-8 LC_COLLATE=en_CA.UTF-8 #> [5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8 #> [7] LC_PAPER=en_CA.UTF-8 LC_NAME=C #> [9] LC_ADDRESS=C LC_TELEPHONE=C #> [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: #> [1] magick_2.3 ggplot2_3.3.0 #> #> loaded via a namespace (and not attached): #> [1] Rcpp_1.0.4 knitr_1.28 magrittr_1.5 tidyselect_1.0.0 #> [5] munsell_0.5.0 colorspace_1.4-1 R6_2.4.1 rlang_0.4.5 #> [9] dplyr_0.8.5 stringr_1.4.0 highr_0.8 tools_3.6.3 #> [13] grid_3.6.3 gtable_0.3.0 xfun_0.12 withr_2.1.2 #> [17] htmltools_0.4.0 assertthat_0.2.1 yaml_2.2.1 digest_0.6.25 #> [21] tibble_2.1.3 lifecycle_0.2.0 crayon_1.3.4 farver_2.0.3 #> [25] purrr_0.3.3 glue_1.3.2 evaluate_0.14 rmarkdown_2.1 #> [29] labeling_0.3 stringi_1.4.6 compiler_3.6.3 pillar_1.4.3 #> [33] scales_1.1.0 pkgconfig_2.0.3 ```
jeroen commented 4 years ago

Thanks. If you inspect the output image, it actually does work in the sense that the output is scaled in the same was as png() does. But I forgot to explicitly mark this in the output image.