geom_abline() 强制 y 轴为 0
有没有办法在不改变比例的情况下添加geom_abline()
?我做了一些挖掘,但没有找到任何专门解决这个问题的东西,并且手动重新缩放轴会删除 abline:
library(tidyverse)
# generate noise that should be roughly 1:1
plot <-
runif(100, 3000, 6000) %>%
as_tibble() %>%
rename(x = value) %>%
rowwise() %>%
mutate(y = rnorm(1, x, 150)) %>%
ggplot(aes(x, y)) +
geom_point()
plot
# geom_abline forces y-axis to 0!
plot +
geom_abline()
# adding in manual scales removes geom_abline
plot +
geom_abline() +
scale_y_continuous(limits = c(3000, 6000))
#> Warning: Removed 1 rows containing missing values (geom_abline).
# reording when `scale_y_continous()` is called doesn't help unfortunately
plot +
scale_y_continuous(limits = c(3000, 6000)) +
geom_abline()
#> Warning: Removed 1 rows containing missing values (geom_abline).
packageVersion("ggplot2")
#> [1] '3.3.4'
由 reprex 包 (v2.0.1)
Is there a way to add geom_abline()
without changing the scales? I've done a bit of digging and haven't found anything that addresses this specifically, and manually rescaling the axes removes the abline:
library(tidyverse)
# generate noise that should be roughly 1:1
plot <-
runif(100, 3000, 6000) %>%
as_tibble() %>%
rename(x = value) %>%
rowwise() %>%
mutate(y = rnorm(1, x, 150)) %>%
ggplot(aes(x, y)) +
geom_point()
plot
# geom_abline forces y-axis to 0!
plot +
geom_abline()
# adding in manual scales removes geom_abline
plot +
geom_abline() +
scale_y_continuous(limits = c(3000, 6000))
#> Warning: Removed 1 rows containing missing values (geom_abline).
# reording when `scale_y_continous()` is called doesn't help unfortunately
plot +
scale_y_continuous(limits = c(3000, 6000)) +
geom_abline()
#> Warning: Removed 1 rows containing missing values (geom_abline).
packageVersion("ggplot2")
#> [1] '3.3.4'
Created on 2022-03-04 by the reprex package (v2.0.1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论