强制原点从0开始 [英] Force the origin to start at 0
问题描述
如何在ggplot2中设置y轴和x轴的原点/截取点?
x轴的线应该恰好在y = Z处。
使用Z = 0或另一个给定的值。
您可能需要稍微调整一下,以确保积分不会被切断(请参阅,例如, How can I set the origin / interception of the y-axis and x-axis in ggplot2? The line of the x-axis should be exactly at y=Z. With Z=0 or another given value. You may need to adjust things a little to make sure points are not getting cut off (see, for example, the point at 这篇关于强制原点从0开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! ylim
不要在这里剪切它。您需要使用 expand_limits
, scale_x_continuous
和 scale_y_continuous
。试试:
pre $ 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#不是您要查找的内容
p + scale_x_continuous(expand = c(0,0))+ scale_y_continuous(expand = c (0,0))
x = 5
和 y = 5
。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
and y = 5
.