What is the most useful output format for graphs?

Before any of you can start in the final vote, let me say that I understand that this question can be subjective and the expected answer can start with “it depends”. However, this is indeed a pressing issue that I am facing as I create more and more charts, and I don’t necessarily know how exactly I will use them, or don’t have time to check the final use of the case right away.

Thus, I use the experience of SO R users to get good reasons to choose one of them between jpg (), bmp (), png (), tiff (), pdf () and, possibly, with which parameters. I do not have experience in R and knowledge in different formats to choose wisely.

Potential use cases:

  • quick browsing or while running algorithms
  • presentations (.ppt mostly)
  • reports (word or latex)
  • publication (internet)
  • storage (without large losses and its later conversion for specific use)
  • all i forgot

Thanks! I am happy to make the question clearer.

+6
source share
3 answers

To expand my comment a bit, there is no real simple answer, but my suggestions are:

  • My first completely flexible choice would be to simply save the final raw data used in the graph (s) and some R code to create the graph (s). Thus, you can easily send the result to any device that suits your specific purpose. It would not be a difficult task to establish yourself a couple of basic templates based on png() / pdf() that you could call.

  • Use svg() device. As @gung noted, saving results using pdf() , svg() , cairo_ps() or cairo_pdf() are your only real options for saving scalable vector images. I tend to svg() instead of pdf() because of the great editing capabilities available with programs like Inkscape. It is also becoming a widespread format for publishing on the Internet (see http://caniuse.com/svg )

  • If, on the other hand, you are a latex user, most of the headaches seem to be resolved by going directly to pdf() - you can usually import and convert PDF files using Inkscape or command line utilities such as Imagemagick if you need to shift the format .

  • To interact with Word / Powerpoint, if you use R on Windows, you can also export directly using win.metafile() , which will give you scalable / component emf images that you can import directly into Word or Powerpoint. I heard about people running R through Wine or using intermediate steps on Linux to get emf files for later use. For Mac, there are roundabout routes as well .

So, we summarize in order of preference.

  • Do not store images at all, save code to create images
  • Use svg / pdf and convert formats as needed.
  • Use export export of win.metafile directly for those cases when you cannot avoid using Word / Powerpoint and will primarily be based on Windows systems.
+11
source

Until now, the answers to this question have recommended the conclusion of graphs in vector formats. This will give you a better result, allowing you to resize your image as you need for any medium on which your image will be displayed (whether it be a web page, document or presentation) , but this is at the expense of computational cost.

For my own work, I often find it much more convenient to save my stories in a raster format with sufficient resolution. You probably want to do this when your data takes a non-trivial amount of time to build.

Some examples of where I find the raster format are more convenient:

  • Manhattan storylines: A plot showing the p-value for hundreds of thousands of millions of DNA markers in the genome.
  • Large heat maps: Clustering the top 5,000 differentially expressed genes between two groups of people, one with the disease and one healthy.
  • Network rendering: When drawing a large number of nodes connected to each other along the edges, redrawing the edges (in the form of vectors) can slow down your computer.

Ultimately, it comes down to a compromise in your own sanity. What annoys you more? Does your computer grind while trying to redraw the image? or find out the exact dimensions to make the image in raster format so that it does not look terrible for your ultimate publishing tool?

+5
source

The main difference that should be kept in mind is raster graphics compared to vector graphics . In general, vector graphics will save options for you later. Of the options you listed, jpeg , bmp , tiff and png are raster formats; only pdf will provide you with vector graphics. Thus, this is probably the best default of your listed options.

+1
source

Source: https://habr.com/ru/post/953286/


All Articles