Reputation: 15298
I don't understand how I can arrange a plot to fill an image of a certain pixel size, with a specific font-size and a small margin. Here is an example plot:
library(ggplot2)
a <-c(1:10); b <- c(1:10)
p <- qplot(a,b)
outPath = "D:/Scratch/"
# 1
png(paste(outPath, '1.png', sep=''), height=400, width=400, res = 120, units = 'px')
print(p); dev.off()
# 2
png(paste(outPath, '2.png', sep=''), pointsize = 20,height=400, width=400, res = 120, units = 'px')
print(p); dev.off()
# 3
png(paste(outPath, '3.png', sep=''), height=400, width=400, res = 250, units = 'px')
print(p); dev.off()
I'm less concerned about the resolution of the image, but I want the font size to be large, in proportion to the overall image (similar to plot #3). The argument pointsize
does not appear to result in any font size changes.I also want the border to be minimized. At the moment, if I use the settings on #3 there is a much larger space around the plot, when compared to the other images. How can I have a plot that has large font, with a small margin?
Upvotes: 2
Views: 2617
Reputation: 162451
Controlling most aspects of the saved image will be more easily accomplished on the ggplot2
side of things (compared to playing with png()
settings).
Within ggplot2
, opts()
can be used to control both the font size, and the widths of figure margins.
Here's an example:
p <- qplot(a,b) +
opts(plot.margin = unit(rep(0,4), "lines"),
axis.title.x = theme_text(size=20),
axis.title.y = theme_text(size=20))
png('1.png', height=400, width=400, res = 120, units = 'px')
print(p); dev.off()
Upvotes: 2