charlesay
charlesay

Reputation: 11

r plots with unequal length of x and y axes

I want to use r to plot data points in an area whose x and y axes are of unequal length.

Specifically, the coordinates range from -136 to 136 on the X Axes, and from 0 to 420 on the y axes.

my naive approach to create a plot that would fit the data with

plot(x=-136:136, y=0:420, type= "n", main="distribution", xlab='xdescr', ylab='ydescr')

fails with

Error in xy.coords(x, y, xlabel, ylabel, log) : 
'x' and 'y' lengths differ

(How) is it possible to create a plot that fits this data? Is it inevitable to create a plot with equal axes length?

edit: the plotted area itself must not be square because the values represent the same (distance) along both axes

edit: I tried the solution suggested here How to get a non-square plot in R?. That doesn't produce a plot like I want - the result is stretched in the wrong direction (landscape-y rather than portrait-y)

Upvotes: 0

Views: 1957

Answers (1)

tyluRp
tyluRp

Reputation: 4768

With ggplot2, you could do the following:

library(tidyverse)

tibble() %>% 
  ggplot() +
  geom_point() + 
  ylim(0, 420) +
  xlim(-136, 136) +
  coord_fixed(ratio = 1)

enter image description here

See: http://ggplot2.tidyverse.org/reference/coord_fixed.html

Upvotes: 1

Related Questions