【发布时间】:2020-02-04 12:35:58
【问题描述】:
无论 x 和 y 比例是多少,我都希望有一条与图表成 45 度角的线。在这个例子中,abline 的截距应该在 x=-3 和 y=-0.5 左右。
下面几行代码:
x <- seq(1,10,1)
y <- sample(1:100, 10, replace=T)
df <- data.frame(x,y)
ggplot(df, aes(x=x, y=y)) +
geom_point() +
geom_abline(slope = 45) +
scale_y_continuous(breaks = scales::pretty_breaks(n = 10), limits = c(-10,10)) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 10), limits = c(-2,10))
【问题讨论】: