簡體   English   中英

在g中將ggplot中的比例設置為1:1

[英]Set the scale in ggplot to be 1:1 in r

我想在下圖中設置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

在此輸入圖像描述

你需要使用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()

在此輸入圖像描述

您需要設置圖形設備的寬度和高度,高度= 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM