2012-08-12 39 views
3

我想将下图中的x轴和y轴设置为具有相同的比例距离(即,x轴上的0.1与0.1上的长度相同y轴)。有什么建议?谢谢。将ggplot中的比例设置为1:1

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

+1

安迪给出了一个想法。你也可以把你的绘图设备的高度大致加倍,如:png(“name”,width = 400,height = 800)' – 2012-08-12 20:08:30

+2

你只需要做par(asp = 1)及其所有设置...哦,不,因为这不是基本的图形,它已经做了25年的方式,这是ggplot和你所学到的一切都是错误的! – Spacedman 2012-08-12 23:18:27

回答

11

您需要使用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

+0

工作过。谢谢。 – Elizabeth 2012-08-13 09:58:06

1

你需要设置你的宽度和你有高度的图形设备的高度= 2 *宽

library('ggplot2') 
library('gridExtra') 
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) 

w <- 550 
png("test.png", width=w, height=2*w, units="px") 

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

dev.off() 

test.png