R ggplot2 use RStudio Chart Zoom settings to save Chart - r

Expanding the question by Jeremy K. in this question here Set ggsave() aspect ratio to the ratio that RStudio's "Zoom" button gives? specifically
I am using ggsave() to save plots from ggplot().
In R-Studio, clicking the "Zoom" button automatically resizes most of my plots to have quite aesthetic proportions, whereas when I try to manually specify the size and aspect ratios, I get plots that don't look as nice.
The answer to the original question and the answers to the similar question R: save figures in the zoomed window with command? both address screen size/resolution but nothing else. As the original question states the RStudio zoom has aesthetic proportions but using the screen width and height only sets the chart size and resolution. The titles, labels etc are all different (tiny in my case) in the saved image versus the original Rstudio zoomed image. Unfortunately using the 'inspect element' suggestion only gives the screen size and not any of the title and label sizes.
Is there a way that I can make ggsave (or any function) use the same aspect ratio or size ALL the same formats that R-Studio's "Zoom" button does?

Related

ggforest - sizing and change landscape to portrait in R

I have a huge ggforest (20 variables) that I cannot show due to embargo of the data. (example below)
Right now the font is 0.7, and I have to make the plots window really big in order to see it all. The plot perfectly fits the PLOT WINDOW as landscape (making it bigger and bigger) the problem is when I narrow the window for a "landscape" view (aka to have a "vertical" plot, the font is illegible. Also the plot window doens't appear to have a scroll down option, and I can only see what the window can fit.
I need help. (also I would like to make the font bigger)

How do I export a ggplot as resizable image?

I'm working on a report with some coworkers in Google Docs (which will eventually be printed). We want to include some plots generated with ggplot. As we edit the document, the space for the images keeps changing slightly--often, we need to resize and/or change the aspect ratio of a plot slightly so that it fits on the page with the accompanying text.
Is there a way to export a ggplot object to an image that is resizable in the same way that plots can be resized in the Export dialog in RStudio?
Google Docs does not support SVG images--dropping an svg on the page simply opens the SVG itself (rather than adding it to the doc), so that's not an option.

Viewer pane is printing in the wrong dimensions

My plots are showing up with the titles way too zoomed it. They are printing like my available space is much smaller than it really is. It was working fine before. I've tried to reset it with dev.off() and par(mfrow=c(2,2)).
plot(mtcars$mpg)
Do you see how the dimensions are weird? I've also tried to clear the preivous plots.
This is the same plot printed on another computer with the viewerport set to about the same size.

How to Adjust Font Size of a ggplot in inkscape?

When I export ggplots from R (with ggsave in svg) to modify them in inkscape, I run into the following problem:
I use the text tool to select some text (axis labels for example). If I want to increase font size in the drop down menu, inkscape only increases the height of the text, width stays the same. I am left with text with the wrong aspect ratio.
This must be due to some type conversion (text to object for example) that is done at some point (ggplot, ggsave or inkscape). Until now I have been unable to figure out how to solve this. So far, I have reverted to deleting the existing text and creating new text in inkscape (adjusting font size works totally normally then)
Code to create input for Inkscape:
tdf <- data.frame()
tpl <- ggplot(tdf) + xlab("testtext")
ggsave(filename="tpl.svg",plot=tpl,height=5,width=8,device="svg")
It appears svglite introduces a textLength parameter which hard-codes the width. Interstingly, Illustrator seems to not care about this when editing the file, but Inkscape does.
You could try another device, svg may not be a great choice as it appears to split words into individual letters, but gridSVG::gridsvg seems to works. Or use a pdf device, which Inkscape can also import.

ggplot2 - autosize chart and axis titles

I have create some ggplot2 bar plots which print fine to screen. When I print in PDF device, however, the chart and axis titles are too large - they sometimes extend past the left and right of the x-axis. None of these charts have any opts() set aside from title/axis-title - its all the defaults. What am I missing here? Is there a way to tell ggplot to auto-size this text so that the charts look good in PDF? Can I do this without explicitly setting opts()?
The best solution I can think of is to create a function to create a theme (like theme_bw()) and give it enough parameters so that its smart about sizing. Will keep this post open for a few days to see if there are any other clever ideas

Resources