强制原点从0开始 [英] Force the origin to start at 0

查看:210
本文介绍了强制原点从0开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ggplot2中设置y轴和x轴的原点/截取点?



x轴的线应该恰好在y = Z处。



使用Z = 0或另一个给定的值。

解决方案

xlim 和 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


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.

解决方案

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))

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆