强制原点从 0 开始 [英] Force the origin to start at 0
本文介绍了强制原点从 0 开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在ggplot2中设置y轴和x轴的原点/截距?
How can I set the origin / interception of the y-axis and x-axis in ggplot2?
x 轴的直线应该正好位于 y=Z
.
The line of the x-axis should be exactly at y=Z
.
使用 Z=0
或其他给定值.
With Z=0
or another given value.
推荐答案
xlim
和 ylim
不在这里切.您需要使用 expand_limits
、scale_x_continuous
和 scale_y_continuous
.试试:
xlim
and ylim
don't cut it here. You need to use expand_limits
, scale_x_continuous
, and scale_y_continuous
. Try:
df <- data.frame(x = 1:5, y = 1:5)
p <- ggplot(df, aes(x, y)) + geom_point()
p <- p + expand_limits(x = 0, y = 0)
p # not what you are looking for
p + scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0))
您可能需要稍微调整一下以确保点不会被切断(例如,请参见 x = 5
和 y = 5
处的点.
You may need to adjust things a little to make sure points are not getting cut off (see, for example, the point at x = 5
and y = 5
.
这篇关于强制原点从 0 开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文