如何使x轴以ggplot2中的零拦截y轴
我有一个简单的线图,其中包含y轴上的点小于零。 x轴位于图的底部,因此不会在y = 0时截距y轴。
如何使x =轴在ggplot2中截取y = 0?
示例代码:
df <- data.frame(x = 1:20, y = seq(-30, 65, by = 5))
p <- ggplot(df, aes(x, y)) +
geom_line() +
geom_hline(yintercept = 0, linetype = "dashed", color = "blue")
p
非常感谢!
I have a simple line graph, that contains points less than zero on the y-axis. The x-axis is at the bottom of the graph, and thus does not intercept the y-axis at y = 0.
How can I get the x=axis to intercept at y=0 in ggplot2?
Example code:
df <- data.frame(x = 1:20, y = seq(-30, 65, by = 5))
p <- ggplot(df, aes(x, y)) +
geom_line() +
geom_hline(yintercept = 0, linetype = "dashed", color = "blue")
p
Many thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
选项1:用
coord_cartesian
选项2:手动移动Xaxis标签。
Option 1: Limit the y-axis display with
coord_cartesian
Option 2: Shift the xaxis label manually.