You can try to save it using the pdf () command:
library(ggplot2) pdf(file="figure.pdf",width=15,height=3) figure <- ggplot(data=mtcars, aes(x=cyl, y=hp)) + geom_point() print(figure) dev.off()
I believe that it also does not work.
Solution (workaround) that should work:
1) save it in svg file
ggplot(data=mtcars, aes(x=cyl, y=hp)) + geom_point() ggsave("figure.svg")
2), then convert it to pdf. For instance. on Linux
rsvg-convert -f pdf -o figure.pdf figure.svg
source share