Can't print to pdf ggplot charts [duplicate]
Solution 1:
Gappy, that smells like the FAQ 7.22 -- so please try print(qplot(1:10))
.
Solution 2:
@Dirk explains why this is happening (auto printing turned off), but an alternative to opening the device, generating the plot on the device, closing the device is ggsave()
. For example:
p1 <- qplot(1:10)
ggsave("p1.pdf", plot = p1)
or via a loop:
outnames <- c("1.pdf", "2.pdf")
for (n in outnames){
p2 <- qplot(1:10)
ggsave(n, plot = p2)
}
At the end of that we have all the generated plots we asked for.
> list.files(pattern = ".pdf$")
[1] "1.pdf" "2.pdf"
[3] "p1.pdf"