Use when asking a question related to saving a ggplot2 object. Part of ggplot2 package. ggsave is a convenient function for saving a plot. It defaults to saving the last plot that you displayed, using the size of the current graphics device. It also guesses the type of graphics device from the extension.
Questions tagged [ggsave]
97 questions
0
votes
1 answer
ggplot with different font family fails to save to pdf
I've seen a lot of suggestions but to my frustration I can't seem to save a simple pdf plot using a different font in ggplot2. I am using ggplot version 3.3.5 in R version
4.1.3 from within Rstudio 2022.07.1 on a mac.
All I use to change the font in…

Jeff Groh
- 135
- 11
0
votes
0 answers
ggsave() with required defaults
I need to save all my ggplots (as svg files) with the requirement below:
"All images must have a minimum resolution of 300 dpi,width 107 mm".
Thus I specified these arguments with ggsave():
library(tidyverse)
plot <- iris %>%
ggplot() +
…

CyG
- 382
- 1
- 12
0
votes
0 answers
How to save ggplots that are stored as lists in a dataframe in separate png files with a single code in R
My ggplots are stored as lists in a dataframe like the picture below. A plot for each id is separately stored in a dataframe. Thus, the dataframe has two columns: id and plots. I want to save each plot of each id as a separate png file in my disk…

ND2020
- 11
- 1
- 2
0
votes
0 answers
Resize plot canvas to actual plot size in R with ggplot2
One of the features of the R plotting machinery that I use more often is png(file=..., width=..., height=..., res=...).
Normally, I set precise values within the function, e.g. png("out.png", height=1500, width=2500, res=250).
I am now making a tool…

schmat_90
- 572
- 3
- 22
0
votes
1 answer
how to crop left side of image in R
I used superheat to make a plot and I want to remove the waste on the left. I tried to save with ggsave and play with the width/height but it is centered so I lose the borders and cant choose to crop just the left side.
Is it doable?

matt
- 1
- 1
0
votes
1 answer
Automatically set ggsave width argument in lapply based on number of observations in dataframe
Let's say I have a list of dataframe and I want to plot them one by one using lapply and geom_tile, and ggsave it locally to my computer:
library(ggplot2)
df1 <- data.frame(grp = rep("A", 30),
point = 1:30,
y =…

benson23
- 16,369
- 9
- 19
- 38
0
votes
1 answer
figuring out panel size given dimensions for the final plot in ggsave (to show count for geom_dotplot)
I'm trying to show the count for dotplot on the x-axis as outlined here:
showing count on x-axis for dot plot
library(ggplot2)
library(grid)
date = seq(as.Date("2016/1/5"), as.Date("2016/1/12"), "day")
value = c(11,11,12,12,13,14,14,14)
dat…

pgitti
- 87
- 7
0
votes
0 answers
Putting multiple ggplots into one PDF with different scales
I'd like to put several plots into one PDF, with a new page for each plot. Each plot is generated with ggplot, and each needs a different scale.
I know how to output individual plots into individual PDFs at the appropriate scale, like so:
plot1…

Mike
- 921
- 7
- 26
0
votes
1 answer
How to save 2 separate ggplots overlapping in the same pdf in R?
I have 2 ggplots: plot1 and plot2
When I show them in R using:
multi.page <- ggarrange(plot1, plot2,
nrow = 1, ncol = 1)
I get the overlap, but when I then want to safe this overlapping images as PDF it is not…

Tahnee
- 77
- 5
0
votes
1 answer
Is there a way to change the device output of officedown::rdocx_document() from .jpg to .emf?
When using officedown::rdocx_document in R Mardown, the Office Word output will include the plots as a .jpg image although my desire is to automatically include the plots of my R markdown in format .emf (Enhanched Metafile).
I know that with the…

Santiago Sotelo
- 180
- 12
0
votes
1 answer
How do you use loop in R with ggpie function and save a filename after the dataframe?
I've leaned heavily on a couple other SO posts already, but can't seem to get past this one.
Here are the references i've used:
Loop with a defined ggplot function over multiple dataframes
Loop in R to create and save series of ggplot2 plots with…

ecp.55
- 15
- 4
0
votes
1 answer
How do I save a phytools phenogram as an image?
I'm using the phenogram() function in the R package phytools to plot a phylogeny along axes of relative time (x) and phenotype, in this case mean annual temperature (y). It shows up in the plot window, but it doesn't seem to exist as a plot object…

nmarieh
- 31
- 3
0
votes
1 answer
Is it possible to pipe a list into ggsave
This works, requires however to create a variable (p):
library(tidyverse)
library(gridExtra)
p <- mtcars %>%
split(.$cyl) %>%
map(~.x %>% ggplot(aes(x=hp,y=qsec)) + geom_point())
ggsave(filename = "myPlot.pdf",
device = "pdf",
…

ChriiSchee
- 667
- 1
- 8
- 20
0
votes
0 answers
Why does ggsave() output a different font from what I'm specifying and is shown in the RStudio viewer?
I downloaded the latest RStudio the other day and I've started running into problems with the font when I use ggsave().
I specify the font as I always have (after loading fonts with extrafont, and it shows up correctly in the RStudio viewer), but…

PupHendo
- 145
- 1
- 8
0
votes
1 answer
Add relative abundance to file name
My code below makes a plot for each species in my dataset, but I was wondering if there was a way to add the relative abundance to the beginning of each file name. (i.e., file for most abundant species "1_speciesA..", 2nd most abundant species is…

Nate
- 411
- 2
- 10