我正在尝试使用一些线段来注释绘图。x 轴最好通过对数转换显示。我正在使用ggplot2
which 处理转换,这也意味着我不应该转换到我的线段的位置。但是当我应用转换时,线段会消失(嗯 - 由于转换,它们不再“适合”到绘图窗口中)。关于如何让他们“跟随”转型的任何建议?
最小的例子:
library(ggplot2)
## Base plot:
B <- ggplot(data = data.frame(X = 10^(1:10), Y = 1:10),
aes(x = X, y = Y)) + geom_point()
## Generate segments:
S1 <- geom_segment(x = 1000, xend = 1000,
y = 3, yend = 5)
S2 <- geom_segment(x = 20, xend = 2.5e9,
y = 8, yend = 7)
## Generate transformation:
T <- scale_x_continuous(trans = "log")
比较以下内容:
B # Basic plot
B + T # Basic plot, transformed
B + S1 + S2 # Basic, untransformed, with segments
B + S1 + S2 + T # Should be transformed with segments: segments missing
我知道我可以只转换段的位置,但我真的更愿意找到一个更ggplot2
风格的解决方案!
破解解决方案:
S3 <- geom_segment(x = log(1000), xend = log(1000),
y = 3, yend = 5)
S4 <- geom_segment(x = log(20), xend = log(2.5e9),
y = 8, yend = 7)
B + S1 + S2
B + S3 + S4 + T #Fine, but not elegant.
谢谢!