啊抱歉,我太蠢了。当我最初尝试时geom_abline(intercept = 0, slope = 1) + geom_abline(intercept = 2, slope = -1)
它看起来不对,所以我想我需要采取不同的方式来做到这一点。但当然它看起来不正确,因为两个轴的比例如此不同 - 线条的角度should那些尺度就那么低。当坐标轴具有相同的比例时,表明该方法是正确的。
第一次尝试:
example_data <- data.frame(x = c(0, 5),
y = c(0, 50)
)
ggplot(example_data, aes(x = x, y = y)) +
geom_vline(xintercept = 1, linetype = "dashed", size = 0.75) +
geom_hline(yintercept = 1, linetype = "dashed", size = 0.75) +
geom_abline(intercept = 0, slope = 1, size = 0.5) +
geom_abline(intercept = 2, slope = -1, size = 0.5) +
geom_point()
当轴刻度相同时:
example_data <- data.frame(x = c(0, 50),
y = c(0, 50)
)
ggplot(example_data, aes(x = x, y = y)) +
geom_vline(xintercept = 1, linetype = "dashed", size = 0.75) +
geom_hline(yintercept = 1, linetype = "dashed", size = 0.75) +
geom_abline(intercept = 0, slope = 1, size = 0.5) +
geom_abline(intercept = 2, slope = -1, size = 0.5) +
geom_point()