noriakis / ggkegg

Analyzing and visualizing KEGG information using the grammar of graphics
https://noriakis.github.io/software/ggkegg
MIT License
210 stars 15 forks source link

Is there any way to achieve a more HD raw image? #19

Closed sunliangxing closed 7 months ago

sunliangxing commented 8 months ago

Hello, I am using ggkegg for drawing

library(ggkegg)
g<-pathway("hsa01240")
ggraph(g,aes(x=x,y=y),layout="auto")+
  overlay_raw_map()+
  theme_void()

image I would like to save a more high resolution image, such as what pathview draws. But pathview can't specify multiple conditions for plotting, and it's not as friendly as ggplot2. Looking forward to your reply, thanks!

noriakis commented 8 months ago

Hi, thanks for raising this important point.

ggkegg uses annotation_raster to incorporate PNG images into the ggplot layer. ggkegg by default used interpolation, however, this makes the image blurry in some instances. Would you try disabling this option and using ggkeggsave function to save the image?

As it depends on the graphic devices used, we can also use another approach, that combines the image of geom layers and the original PNG image. I implemented the output_overlay_image function in the devel branch (installation by devtools::install_github("noriakis/ggkegg", ref="devel")).

This outputs two images and combines them inside the function, yielding the same resolution as the original image. However, this approach must extract the main panel from the ggplot object, and thus the legend (or the title, the axis, etc... made by ggplot) will be omitted from the output. The legend can be placed inside the main panel (e.g. theme(legend.position=c(0.1, 0.1))), or can be placed outside the image by specifying the option (with_legend_image).

The examples are now described in the bookdown. I hope this helps and if you have any opinions or a better way of rendering, please feel free to report them!

sunliangxing commented 8 months ago

Thank you very much, I am able to save high res images using ggkeggsave, however when I save a pdf, the clarity is nowhere near as good as a png. image But I can use convert in linux to make png2pdf also achieve good results

convert test.png test.pdf

image

noriakis commented 8 months ago

Glad that it helped. As you stated, saving in PDF file format is not feasible for saving in high resolution as the original PNG image is rasterized. I think it is appropriate to convert it that way, and thanks for sharing.

On Sun, Feb 4, 2024 at 10:43 AM sunliangxing @.***> wrote:

Thank you very much, I am able to save high res images using ggkeggsave, however when I save a pdf, the clarity is nowhere near as good as a png. image.png (view on web) https://github.com/noriakis/ggkegg/assets/71911098/3d251de9-80c5-464a-b009-924f407bfbd8 But I can use convert in linux to make png2pdf also achieve good results

convert test.png test.pdf

image.png (view on web) https://github.com/noriakis/ggkegg/assets/71911098/355fdf0a-6a63-4cc8-9d51-6f28d186cfd8

— Reply to this email directly, view it on GitHub https://github.com/noriakis/ggkegg/issues/19#issuecomment-1925532251, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHNHVPZV3JEXY4Z5NAT76J3YR3RVBAVCNFSM6AAAAABCWKTF7CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRVGUZTEMRVGE . You are receiving this because you commented.Message ID: @.***>