Mick
Mick

Reputation: 3

In R, How do I set plot size when plotting to raw png (byte array)

I was able to save a plot to a variable by following In R, how to plot into a memory buffer instead of a file?

I haven't been able to set the height and width of the resulting image without crashing R and my Java program. (R is called from a Java program using REngine running on Mac OSX Lion).

Before plotting, I have tried both:

windows.options(width=2, height=2)

and

Cairo(width=2, height=2,file='/dev/null')

No dice.

Upvotes: 0

Views: 1457

Answers (2)

Mick
Mick

Reputation: 3

Cairo(width=250, height=250, '/dev/null', 'png')

Upvotes: 0

Eric Fail
Eric Fail

Reputation: 7928

First, it is always helpful if you submit a working example.

Second, have you read the ?png?

Third, if you share your end goal it is easier for us to suggest possible solutions and understand your problem (maybe you can get out of running R in a Java program).

Here is how I would do it, though it does sound as you do not what the png on your hard disk?

png("mygraph.png",  width = 480, height = 480, units = "px")
plot(sin, -pi, 2*pi)
dev.off()

Let me know if this works for you or try to be more specific in your question.

Best, Eric

Upvotes: 3

Related Questions