Re: [R] ggsave() with width only

2021-09-20 Thread Ivan Calandra
Dear Adam, This would work indeed, but then the default aspect ratio (1.618) would be used. I could as well calculate the height from the width and aspect ratio. Unfortunately, this doesn't help me in my case (but as I said, I have found a workaround). Thank you again. Ivan -- Dr. Ivan Cal

Re: [R] ggsave() with width only

2021-09-20 Thread Adam Wysokiński via R-help
Dear Ivan, I think you don't need to provide the aspect ratio, as this should work as well: save_plot("/tmp/plot.png", p, base_width = 5, base_height = NULL) -- Regards, Adam Wysokiński On 9/20/21 16:09, Ivan Calandra wrote: Dear Adam, The function cowplot::save_plot() actually doesn't help

Re: [R] ggsave() with width only

2021-09-20 Thread Ivan Calandra
Dear Adam, The function cowplot::save_plot() actually doesn't help in my case because I need to know the aspect ratio (which I don't in advance). If I knew the aspect ratio, I could calculate the height from the width or vice-versa, and then I could use ggplot2::ggsave(). I have found a work

Re: [R] ggsave() with width only

2021-09-14 Thread Ivan Calandra
Thank you Adam! I'm a bit surprised that an extra package is needed for this, but why not! Best, Ivan -- Dr. Ivan Calandra Imaging lab RGZM - MONREPOS Archaeological Research Centre Schloss Monrepos 56567 Neuwied, Germany +49 (0) 2631 9772-243 https://www.researchgate.net/profile/Ivan_Calandra

Re: [R] ggsave() with width only

2021-09-13 Thread Adam Wysokiński via R-help
Hi, Instead of ggsave(), use save_plot() from the "cowplot" package: library(ggplot2) library(cowplot) x <- 1:10 y <- x^2 df <- data.frame(x, y) p <- ggplot(df, aes(x, y)) + geom_point() save_plot("/tmp/plot.png", p, base_aspect_ratio = 1, base_width = 5, base_height = NULL) -- Regards, Adam W

Re: [R] ggsave() with width only

2021-09-06 Thread Duncan Murdoch
On 06/09/2021 11:06 a.m., Ivan Calandra wrote: Yes Jeff, you are right. I hate manually editing figures too, but sometimes I find it's still the easiest way (e.g. when you submit your paper several times when journals have differing guidelines, or when you build figures from several (sub)plots +

Re: [R] ggsave() with width only

2021-09-06 Thread Ivan Calandra
Yes Jeff, you are right. I hate manually editing figures too, but sometimes I find it's still the easiest way (e.g. when you submit your paper several times when journals have differing guidelines, or when you build figures from several (sub)plots + other images, or when you combine plots that

Re: [R] ggsave() with width only

2021-09-06 Thread Jeff Newmiller
I don't always use rmarkdown to write papers either, but you can capture figures from it. I avoid hand editing figures like the plague of irreproducibility. But sometimes you get stuck in an approach... I cannot answer your original post, but wanted to point out that it may not actually be nece

Re: [R] ggsave() with width only

2021-09-06 Thread Ivan Calandra
Thank you Jeff for your answer. I do use rmarkdown but I do not write papers completely with it. I do output a report in HTML but I also like to export the plots as PDF so that I can edit them (using Inkscape or similar) if and as needed. And because I like to have both the HTML report includin

Re: [R] ggsave() with width only

2021-09-06 Thread Jeff Newmiller
I use an rmarkdown file to generate consistent output figures and tables for html or Word. I just use Rnw files directly if I am generating LaTeX. I do not use R files for building output... and I never use ggsave. So you might consider altering your approach to bypass the question entirely. On

[R] ggsave() with width only

2021-09-06 Thread Ivan Calandra
Dear useRs, I produce several independent ggplot2 plots and I would like to save them to a fixed width (for publications), but the height (and therefore aspect ratio) is different from plot to plot. How can I save my plots with ggsave() supplying only a fixed width but without knowing the he