DavidC
DavidC

Reputation: 1441

set default device (png) with default height and width

I'm setting the default device to PNG options(device="png").

For one plot, I can make a PNG in R with particular dimensions using png(...):

v <- 1:10
png("squared.png", width = 960, height = 480)
plot(v, v**2)
dev.off()

But I want to set the default height/width (just like I'm setting the default device) so that all plots come out with my desired height and width.

Upvotes: 2

Views: 1639

Answers (2)

DavidC
DavidC

Reputation: 1441

Ah, this is what I'm looking for:

options(device = function() png(width = 960))

The device argument should be

a character string giving the name of a function, or the function object itself, which when called creates a new graphics device of the default type for that session...

Using a function instead of the string "png" gives me the flexibility I need.

Upvotes: 3

Michele Usuelli
Michele Usuelli

Reputation: 2000

Why don't you re-define png? If you type png into the console, R will display the function code. You can copy and paste it into an R script, changing its defaults. Then, the autocomplete of the function arguments will still work.

Upvotes: 1

Related Questions