【发布时间】:2021-08-20 09:51:57
【问题描述】:
我想为 ggplot 图创建一条附加线,该线会根据显示值的比例进行动态调整。我想添加这一行,以便快速查看其中一个类别是否始终大于另一个类别。 因此,如果我可以将线添加到独立于关卡的每个情节中,那就太好了。
library(dplyr)
library(ggplot2)
test <- structure(list(Date = c("202107", "202106", "202104", "202102",
"202101", "202105", "202103"), Val1 = c(199165942214.504, 200405660266.164,
194931793612.389, 187140775347.389, 186193256330.389, 196323803492.389,
191885428112.389), Val2 = c(194546158558, 195351933631, 188748709692,
181522458543, 180653727026, 190427709692, 186599848808)), row.names = c(NA,
-7L), class = c("tbl_df", "tbl", "data.frame")
test %>%
ggplot(., aes(x=Val1, y = Val2)) +
geom_point()
# Not working, because of the wrong intercept.
test %>%
ggplot(., aes(x=Val1, y = Val2)) +
geom_point() +
geom_abline(intercept = 0, slope = 1, size = 0.5)
此答案中提出的解决方案显然不起作用https://stackoverflow.com/a/67182543/5795592
【问题讨论】: