Search code examples
rggplot2mappingsurface

How to plot chart by ggplot2 with fixed scale?


I need to draw different kind of pics using ggplot2 in R and it have to be in proper scale when I print it. It means that I have to define exact image and chart size, the same scale of x/y-axes.

Could you please advice me what kind of options I should to use?

ggplot(Surface, aes(x, y, z = z)) +
  geom_contour_filled(binwidth = 10, alpha = 0.6) +
  geom_textcontour(binwidth = 20, size = 2.5)

Solution

  • Maybe you want to use coord_fixed with ratio argument:

    aspect ratio, expressed as y / x

    Here is your code:

    library(ggplot2)
    ggplot(Surface, aes(x, y, z = z)) +
      geom_contour_filled(binwidth = 10, alpha = 0.6) +
      geom_textcontour(binwidth = 20, size = 2.5) +
      coord_fixed(ratio = 2/1)