Skip to content

ggsave error with ggplot 3.3.5 when run using Rscript #4550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rzambre opened this issue Jul 7, 2021 · 3 comments
Closed

ggsave error with ggplot 3.3.5 when run using Rscript #4550

rzambre opened this issue Jul 7, 2021 · 3 comments

Comments

@rzambre
Copy link

rzambre commented Jul 7, 2021

When running with Rscript, ggsave throws an error with ggplot 3.3.5. I do not see the error with ggplot 3.3.3.
Usage and example below.

R version 4.0.2


Example plotter.R (run with any csv file with any random data with a minimum of two columns):

library(tidyverse)

latency <- read.csv("latency.csv", header=TRUE)

plot_and_save <- function(df, xval, yval, title, subtitle, xlabel, file) {
  p <- ggplot(df, aes_string(x=xval, y=yval, group=1)) +
    geom_line(size = 0.5) +
    geom_point(size = 1.5, alpha = 1) +
    theme_minimal() +
    expand_limits(y=0) +
    xlab(xlabel) +
    ggtitle(title, subtitle = subtitle) +
    theme(
      axis.text.x = element_text(angle=90,hjust=1),
      axis.title.y = element_blank()
    )
  ggsave(filename=file, p, device=pdf, dpi=500)
}

plot_and_save(df=latency,
              xval="bytes",
              yval="lat_avg",
              title="Ping pong",
              subtitle="Latency (us)",
              xlabel="Message size (bytes)",
              file="latency.pdf"
)

Running and output:

Rscript ./plotter.R
Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf",  :
  unused argument (filename = "latency.pdf")
Calls: plot_and_save -> ggsave -> dev -> do.call
Execution halted
@yutannihilation
Copy link
Member

Thanks, this seems the same issue: #4539. But, in this case, maybe you can just remove device=pdf argument as it's automatically inferred from the file extension?

@rzambre
Copy link
Author

rzambre commented Jul 8, 2021

Yes, removing device=pdf worked with 3.3.5

@yutannihilation
Copy link
Member

Thanks for confirming. Let me close this and track the problem on #4539.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants