1

I am not sure if this question is related to R or tikzDevice.

I simply use R and the command plot(1). The resulting graphic behave like a vector graphic. It's aspect ratio depends on the ratio of the window it is displayed in.

Can I set the aspect ratio explicite while calling plot()?

xlim doesn't affect the graphic output itself - just the content (the numbers on the x-axis).

Maybe there is a way with tikzDevice to fix the aspect ratio? The script I use with tikzDevice looks like this.

#!/usr/bin/R -f

# load the library
library(tikzDevice)

# the output file
tikz('plot.tex')

#
plot(1, xlab='X-Axis', ylab='Y-Axis')
dev.off()

@Moderators: Please add the tag 'tikzDevice'.

buhtz
  • 10,774
  • 18
  • 76
  • 149
  • 1
    Does that help you? http://stackoverflow.com/questions/8693558/how-to-define-fixed-aspect-ratio-for-scatter-plot – David Nov 19 '15 at 14:43

1 Answers1

-1

The help page ?plot includes the asp argument which is used to control aspect ratio (more details are on the ?plot.window page).

I don't know if the tikz device handles this differently (because the height and width of the plotting are may change after the plot is created), but the place to start is trying something like:

plot(1, asp=1)

and then make sure that the size of the plotting area is the same in the final document.

Edit

You may not see much change in the plot when you only plot 1 point, but try the following commands to see the effect of setting asp:

theta <- seq(0,2*pi, length=200)
plot(cos(theta),sin(theta))
plot(cos(theta),sin(theta), asp=1)

For regular R and Rstudio at the defaults (on my computer at least) there is a visible difference in the 2 plots. I have not tried this with a tikz device.

You might also try the squishplot function from the TeachingDemos package (I have never tried it with tikz devices, but in regular R it works as another way to set the aspect ratio):

library(TeachingDemos)
op <- squishplot(c(-1,1),c(-1,1), asp=1)
plot(cos(theta),sin(theta))
par(op)
Greg Snow
  • 48,497
  • 6
  • 83
  • 110
  • This parameter only affects the min-max-values for the x and y axis but change nothing on the graphic itself. – buhtz Nov 19 '15 at 15:53
  • @buhtz, you won't see much effect on the aspect ratio with only 1 point being plotted, see the new example above. – Greg Snow Nov 19 '15 at 18:01
  • @buhtz, also did you try setting `asp` using `plot.window` instead of directly in the `plot` function call? – Greg Snow Nov 19 '15 at 18:04
  • I am not sure how to "integrate" that into my plot()? `plot.window` only opens an empty window. And btw: the aspect ratio of the window is even `1` no matter what the value of `asp` is. – buhtz Nov 21 '15 at 09:44
  • @buhtz, maybe if you show us more of what you are actually trying to accomplish we can give better advice. Aspect ratio does not matter much if you only plot a single point, so I assume that you want to add to the plot (and `plot.window` starts with a blank plot so that you can add whatever you want to it). I tried my example above with a tikz plot and including `asp=1` made a difference. Show us what you are actually doing (real code), what you want the result to be like, and how your result differs. – Greg Snow Nov 23 '15 at 17:14