这个问题在这里已经有了答案:
Force the origin to start at 0
(3 个回答)
5个月前关闭。
我有一个正 x 和 y 值的数据框,我想在 ggplot2
中显示为散点图.这些值远离点 (0,0) 聚集,但我想在图中包含 x=0 和 y=0 线以显示总体幅度。我怎样才能做到这一点?
set.seed(349)
d <- data.frame(x = runif(10, 1, 2), y = runif(10, 1, 2))
ggplot(d, aes(x,y)) + geom_point()
但我想要的是大致相当于这个的东西,而不必指定限制的两端:
ggplot(d, aes(x=x, y=y)) + geom_point() +
scale_x_continuous(limits = c(0,2)) + scale_y_continuous(limits = c(0,2))
最佳答案
一种选择是只锚定 x 和 y 最小值,但不指定最大值
ggplot(d, aes(x,y)) + geom_point() +
scale_x_continuous(limits = c(0,NA)) +
scale_y_continuous(limits = c(0,NA))
关于r - 如何锚定轴限制的一侧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24942953/