开发者

Is there a way to set new defaults for ggsave?

Instead of having to repeat "height= 4, width= 4, dpi= 72" with every call . . .

I once tried library(defaults) for a problem like this, but it did not behave well. I asked a question about it on R-help, but it seemed like no one uses it.

It looks like par("din") is coming from the X11 device that I have running, but that's not going to be the device that ggsave() uses when I call it, I don't think, because I'm either saving to a .png or a .pdf -- PDFs are no good for my scatter and tile plots. Granted, the PDFs scale much better when I bring them into my LaTeX document, but it seems like this is a desirable leve开发者_开发百科l of control in general.

Thanks for your ideas.


This may not be the best way, but you can write a wrapper function with different height and width defaults. For example

my.ggsave <- function(filename = default_name(plot), height= 4, width= 4, dpi= 72, ...) {
ggsave(filename=filename, height=height, width=width, dpi=dpi, ...)
}

Now we can test to see if my.ggsave does what we want it to:

ggplot(data.frame(x=1:10), aes(x=x, y=x)) + geom_point()
ggsave("normal_ggsave.png")

and make sure we can pass additional arguments to ggsave if we need to:

my.ggsave("four_by_four_600.png", dpi=600)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜