Skip to content
Justice Tech School

Saving Plots

png() and dev.off() or ggsave write images to files.

Example
f <- tempfile(fileext = ".png")
png(f, width = 400, height = 300)
plot(1:3)
dev.off()
print(file.exists(f))
unlink(f)

Exercise

Close the device.

.off()

Quiz Test

What does dev.off do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.