0

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.

Community
  • 1
  • 1
Mick
  • 3
  • 2

2 Answers2

3

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

Eric Fail
  • 8,191
  • 8
  • 72
  • 128
  • Thanks Eric, I needed to specify 'png' in the Cairo call, then I can pass in height and width as pixels. I figured this out while thinking about your questions. Cairo(250, 250, '/dev/null', 'png') – Mick Apr 01 '12 at 21:08
  • @ Mick; Glad you figured it out. – Eric Fail Apr 01 '12 at 21:14
0
Cairo(width=250, height=250, '/dev/null', 'png')
pjumble
  • 16,880
  • 6
  • 43
  • 51
Mick
  • 3
  • 2