Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将ggplot中的比例设置为r中的1:1_R_Ggplot2 - Fatal编程技术网

将ggplot中的比例设置为r中的1:1

将ggplot中的比例设置为r中的1:1,r,ggplot2,R,Ggplot2,我希望在下图中设置x轴和y轴,使其具有相同的缩放距离(即x轴上的0.1与y轴上的0.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

我希望在下图中设置x轴和y轴,使其具有相同的缩放距离(即x轴上的0.1与y轴上的0.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

df您需要使用
coord_equal()


df您需要将图形设备的宽度和高度设置为高度=2*width

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

安迪给出了一个想法。您也可以通过在绘图设备中将我们的高度大致增加一倍来解决这个问题,如:
png(“name”,width=400,height=800)
您只需执行par(asp=1)及其所有设置。。。哦,不,因为这不是基础图形,25年来一直如此,这是ggplot,你所学的一切都是错误的!
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()