From @|mon@urb@nek @end|ng |rom R-project@org  Fri Feb 12 21:32:02 2021
From: @|mon@urb@nek @end|ng |rom R-project@org (Simon Urbanek)
Date: Sat, 13 Feb 2021 09:32:02 +1300
Subject: [Rd] 
 Request for a crop option on R's standard plot context menu
In-Reply-To: <CWXP123MB3429545A65FE3EF62D70CF318F8C9@CWXP123MB3429.GBRP123.PROD.OUTLOOK.COM>
References: <CWXP123MB3429545A65FE3EF62D70CF318F8C9@CWXP123MB3429.GBRP123.PROD.OUTLOOK.COM>
Message-ID: <53D47F27-ABEF-4369-B42B-7FB0295C6381@R-project.org>

Toby,

R provides more convenient ways for this - using window devices for any output other than screen is not its intended function. I would recommend using the off-screen devices devices such as pdf() or png() to generate output which also gives you far more control. Also please note that the amount of margins you include in the plots is entirely up to you, it should not be necessary to crop anything after the fact if you set mar/oma to the desired values.

That said, it is just a simple one-liner "magick::image_trim('foo.png')" to trim an image if you want to go that route.

Cheers,
Simon



> On Feb 12, 2021, at 5:55 AM, Marthews, Toby R. via R-devel <r-devel at r-project.org> wrote:
> 
> Dear R Dev,
> 
> I hope you don't mind a request for a feature from a long-time R user (happily using R since 2005).
> 
> I use R for lots of plotting for my work, e.g. for my current project I have a script that generates 300 plots. I generally copy these all as bitmaps and put them directly into a Word document for my report (see e.g. attached screenshot).
> 
> I am always required to maximise the plots to get the best resolution, but that always means I get lots of white space when I copy the plot into Word. Cropping them takes a reasonable amount of time (e.g. an entire day to crop all 300 for this project).
> 
> I'm wondering whether it would be possible to have an option added to the plot window context menu for "Cropped bitmap" or "Crop whitespace"? I think this would be VERY useful because all the online tools I've seen for batch-cropping a set of images require the same crop to be applied to all images (e.g. https://www.youtube.com/watch?v=icbpS0OH9a0 ) and that's not the case for my plots (some of my plots are panel plots, some simpler plots).
> 
> I know it's a bit cheeky to ask for something that I have no idea how to code up myself: I am just hoping that this feedback might go somewhere useful. R can really do 99% of things kind of perfectly so it seems churlish to point out the 1%, but if this is an easy thing to add in then at least I would use it pretty much every project I work on!
> 
> Many thanks and best regards,
> 
> Best regards,
> 
> Toby
> 
> PS. I know I could modify my script so that it creates windows of exactly the right size (dev.new), but doing that would mean I would have to recalculate the sizes if I changed anything on the plots at all (e.g. aspect, x label) so I would lose probably more time pursuing that option. Also, I've found that using lots of dev.new commands makes it difficult for colleagues who use RStudio to use my scripts.
>   I am also aware I could export these images as pdfs, but then I would have to open 300 pdfs, extract the images and crop them all in 3rd party software. Again, perfectly possible but I am searching for a slightly quicker solution (!).
> 
> 
> Dr Toby Marthews
> 
> UKCEH Band 6 Researcher in Global Surface Science (Hydro-Climate Risks)
> 
>   Mob: +44 753 2168305, web: www.tobymarthews.com<http://www.tobymarthews.com>
> 
> 
> 
> This email and any attachments are intended solely for the named recipients and are confidential. If you are not the intended recipient please reply to the email to highlight the error and delete this email from your system; you must not use, disclose, copy or distribute this email or any of its attachments. UKCEH has taken every reasonable precaution to minimise risk of this email or any attachments containing viruses or malware but the recipient should carry out its own virus and malware checks before opening the attachments. UKCEH does not accept any liability for any losses or damages which the recipient may sustain due to presence of any viruses. Opinions, conclusions or other information in this message and attachments that are not related directly to UKCEH business are solely those of the author and do not represent the views of UKCEH. We process your personal data in accordance with our Privacy Notice, available on the UKCEH website.
> https://www.ceh.ac.uk/privacy-notice
> <Plot context menu.png>______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


	[[alternative HTML version deleted]]



[Rd] Request for a crop option on R's standard plot context menu
Simon Urbanek