rstudio / thematic

Theme ggplot2, lattice, and base graphics based on a few simple settings.
https://rstudio.github.io/thematic/
Other
244 stars 10 forks source link

[R] for-loop code for multiple graph is not working with message "In png(file = ) : opening device failed" #128

Closed boram1024 closed 10 months ago

boram1024 commented 1 year ago

I want multiple plot using for loop in R my code is below...but it's not working following the massage

Error in png(filename = mypath) : png() In addition: Warning messages: 1: In png(filename = mypath) : 2: In png(filename = mypath) : opening device failed

what is the problem?

for(i in 0:9) {
  start <- 1+i*10
  end <- (1+i)*10
  plot_title <- df$time[[start]]
  mypath <-  file.path("C:/Users/DS266/Desktop/calibration", paste("myplot_", plot_title, ".png", sep = ""))
  par(mar=c(5,5,5,5))
  plot(df$time[start:end],
       df$flow_3[start:end])
       # type = 'b',
       # pch = 6,
       # cex = 0.5,
       # col = 6,
       # xlab = "",
       # ylab = "",
       # ylim = c(0,6),
       # axes = T,
       # ann = F)
  png(file = mypath)
  dev.off()
}
cpsievert commented 10 months ago

Pretty sure you want to call png() before plot()?

Closing since it doesn't seem like this is a thematic specific issue