Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the scale in ggplot to be 1:1 in r

Tags:

r

ggplot2

I would like to set the x and y axis in the following plot to have the same scale distance (i.e. 0.1 on the x axis is the same length as 0.1 on the y axis). Any advice? Thanks.

df <-data.frame(x = c(0,0.2,0.5), y = c(0.6,0.7,0.9))

p <-ggplot(df, aes(x, y, ymin=0, ymax=1, xmin=0, xmax=1))

p <- p + geom_point(alpha=2/10, shape=21, fill="blue", colour="black", size=5)

grid.arrange(p, p,ncol=1)

p

enter image description here

like image 434
Elizabeth Avatar asked Dec 11 '22 23:12

Elizabeth


1 Answers

You need to use coord_equal()

df <-data.frame(x = c(0,0.2,0.5), y = c(0.6,0.7,0.9))
p <-ggplot(df, aes(x, y, ymin=0, ymax=1, xmin=0, xmax=1))
p <- p + geom_point(alpha=2/10, shape=21, fill="blue", colour="black", size=5)

p + coord_equal()

enter image description here

like image 108
Andy Avatar answered Jan 05 '23 10:01

Andy