I'm making a bunch of line graphs in R with ggplot2 and I want to save them as jpegs. However, I would like to make the graphs bigger or higher resolution, so that if you zoom in on the graphs when viewing them they don't look so pixelated.
Here's a code snippet:
library("ggplot2")
p <- ggplot(df1)
p <- p +
geom_line(aes(time, ee_amt, colour="ee_amt"), size = 2) +
geom_point(aes(time, ee_amt, colour="ee_amt"), size = 2)
jpeg("G:\\Auto Parts\\sample.jpg")
print(p)
dev.off()
Use ggsave
and specify the dpi
you desire.
library(ggplot2)
df <- data.frame(x = 1:10, y = rnorm(10))
my_plot <- ggplot(df, aes(x,y)) + geom_point(size = 4)
ggsave(my_plot, file="sample.jpg", dpi = 600)
Save plots as PostScript, and use ImageMagick convert
to convert to JPEG at the desired density, e.g.:
ggsave(my_plot, file="foo.ps")
Then, to make a 300 dpi JPEG version:
$ convert foo.ps -density 300 foo.jpeg
You'll have a smaller file that you can render at any resolution you want and any bitmap format that ImageMagick supports.
If this is for the web, consider converting to SVG or PDF formats:
$ convert foo.ps foo.svg
You can embed SVG in an iframe
pretty easily, and this facilitates smooth zooming with small file sizes, compared with high-resolution bitmaps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With