我在 ggplot 中发现了一个相当令人困惑的功能,同时尝试在 log10 尺度上注释段。以下代码生成以下图:
library(ggplot2)
dat <- data.frame(x = x <- 1:1000, y = log(x))
ggplot(dat, aes(x = x, y = y)) +
geom_line(size = 2) + scale_x_log10() +
annotate("segment", x = 0, xend = log10(100), y = log(100), yend = log(100), linetype = 2) +
annotate("segment", x = log10(100), xend = log10(100), y = 0, yend = log(100), linetype = 2)
而这就是我所追求的:
ggplot(dat, aes(x = x, y = y)) +
geom_line(size = 2) + scale_x_log10() +
annotate("segment", x = 0, xend = log10(100), y = log(100), yend = log(100), linetype = 2) +
annotate("segment", x = 100, xend = log10(100), y = 0, yend = log(100), linetype = 2)
换句话说,我必须在 x 轴上对线段的端点进行 log10 转换,而不是开始。这种行为有合乎逻辑的解释吗?我知道aes()
转换是否......但在这种情况下,x 轴上的转换应该是统一的(嗯,log10),对吧?
我正在研究:
R version 3.0.0 (2013-04-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
ggplot2_0.9.3.1