Questions tagged [ggsave]

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.

97 questions
1
vote
0 answers

R ggsave dpi is always 72 in MacOS

I am using m1 Mac. When I use ggsave to save a 300 dpi png or other formats, Mac always will convert it to 72 dpi. For example, library(tidyverse) a <- ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point(size=2, shape=23)+ theme_bw(base_size =…
zzw0034
  • 21
  • 2
1
vote
1 answer

How to conditionally download a plot?

The below reproducible code allows the user to select either a data table or a plot of the data for viewing (via input$view). I'm trying to create a conditional around the downloadHandler() so that if the user is viewing the data table and chooses…
1
vote
0 answers

Warning message prevents ggrepel from saving ggmap as image file

I'm trying to save a map with coordinates and labels (using ggrepel) as an image file. This is my code: library(ggplot2) library(ggmap) library(ggrepel) library(grid) lon = c(8.5213, 9.9576, 11.0621, 12.1844, 9.1307, 8.4090, 11.0549, 9.0997, …
AlexLee
  • 429
  • 4
  • 11
1
vote
1 answer

Why is ggsave not saving my plot to my computer?

Hi I'm trying to save high quality (300 dpi) images using RStudio but no luck so far. I've looked around a lot on the internet but no answer seems to work. Even when I run the code below, no file shows up on my computer. Any help is…
luisa
  • 15
  • 1
  • 5
1
vote
1 answer

The 4.1.2 R version leads to some issues with ggplot

I have a list of df Measurements_l for which I used to work with lapply and a function containing ggplot to plot each list : Measurements_l <- split(Measurements,list(Measurements$Sample.type,Measurements$Site), drop=TRUE) …
Sylvain
  • 133
  • 1
  • 10
1
vote
1 answer

ggsave() fails with Error in png_dev(..., res = dpi, units = "in") : unable to start png() device

When I try to save a ggplot to a new directory with ggsave(), I get an error. library(ggplot2) ggplot(mtcars, aes(x = cyl)) + geom_bar() ggsave("current_folder/new_folder/new_plot.png") Produces the error: Saving 11.3 x 7.32 in image Error in…
Sam Firke
  • 21,571
  • 9
  • 87
  • 105
1
vote
0 answers

Define a function for "height" in ggsave depending on the number of rows in facet_grid

For each element of my list of data (data_l) I got a plot with this simple function : data_l <- split(data,list(data$Sample.type,data$Locality), drop=TRUE) lapply(names(data_l), function(i){ ggplot(data_l[[i]], aes(Date, Concentration, group =…
Sylvain
  • 133
  • 1
  • 10
1
vote
0 answers

ggsave doesn't save plots

I have been using ggsave for years with no problem. But now it suddenly stopped saving plots. It saves an empty png. Here's an example (very primitive to show that the problem is not in the plot itself): col2=brewer.pal(n=11, name =…
SKay
  • 23
  • 4
1
vote
0 answers

ggplot loses scale_color_manual when saving to png with ggsave

I am having a strange issue where saving a ggplot figure that I make does not maintain the colors I set using scale_color_manual. I have made a reproducible example (with some editing) using the mtcars dataset. plot1 <- ggplot(data = mtcars %>%…
Patrick
  • 915
  • 2
  • 9
  • 26
1
vote
1 answer

How to auto-adjust size of ggarrange (ggplotGrob + ggplot graphs) into a pdf in R?

I would like to save as pdf a combi of three graphs - one ggplot and two ggplotGrob. With the codes I am trying, the figures are on top of each other. library(ggplot2) library(condformat) library(ggpubr) data(iris) graph1 <- ggplot(data=iris,…
CamillaM
  • 23
  • 5
1
vote
1 answer

ggsave error with wmf unused argument (bg = "white")

ggsave in ggplot (3.3.4) generates this error: Error in grDevices::win.metafile(...) : unused argument (bg = "white") However, I can export the plot interactively using the RStudio | Plots menu. reproducible example: library(tidyverse) e <-…
David Weis
  • 11
  • 2
1
vote
1 answer

Saving dendrograms modified with dendextend in R

I want to rotate the order of several groups in a dendrogram and managed to do it with dendextend. However, when I try to save the plot with ggsave I end up with the original dendrogram, unrotated. Is there a way to save the rotated dendrogram with…
sternegr
  • 13
  • 2
1
vote
2 answers

Saving ggplots with greek alphabets in pdf

Here is a minimal example of the problem I face: data.frame(Time=as.factor(c(0,5,10,15,20,25,30,35)), Value=c(0,2,4,6,8,6,5,6))%>% ggplot(aes(x=Time,y=Value))+ geom_point()+ ylab("\U0394 O.D") ggsave("image.pdf", dpi = 1200) I…
Ginko-Mitten
  • 304
  • 1
  • 11
1
vote
1 answer

Exporting images in R: Cairo and ggsave increasing specified dimensions

I'm trying to export a figure with dimensions 90x150 mm with 300 dpi using the ggsave() and Cairo(). The problem is that even though I correctly specified the figure dimensions on the code, they ended up far bigger then expected (281x468 mm). Here's…
Gabriel Lucas
  • 170
  • 1
  • 2
  • 14
1
vote
2 answers

Is there a way to print Unicode characters in a plot using ggsave on macOS Big Sur & R 4.0.3

I'm trying to print a ggplot2 plot that contains a unicode character (specifically Japanese, but that shouldn't matter) to PDF. System locale is UTF8 on macOS, so I can use Unicode characters everywhere else. Unfortunately, ggsave only prints dots,…