当主要具有对数刻度时,如何让ggplot2显示插图?

And*_*ele 3 r graph ggplot2 insets

我有一个在x轴上有对数刻度的图形.尝试创建插图不起作用,但如果将比例更改为线性,则似乎没有问题.有没有办法解决这个问题,还是ggplot的限制?

这有效:

p = qplot(1:10, 1:10)
g = ggplotGrob(qplot(1, 1))
p + annotation_custom(grob = g, xmin = 3, xmax = 6, ymin = 6, ymax = 10)
Run Code Online (Sandbox Code Playgroud)

这不是:

p = qplot(1:10, 1:10, log='x')
g = ggplotGrob(qplot(1, 1))
p + annotation_custom(grob = g, xmin = 3, xmax = 6, ymin = 6, ymax = 10)
Run Code Online (Sandbox Code Playgroud)

Tro*_*roy 6

使用对数刻度,x被解释为0到1:

p = qplot(1:10, 1:10, log='x')
g = ggplotGrob(qplot(1, 1))
p + annotation_custom(grob = g, xmin = 0.3, xmax = 0.9, ymin = 6, ymax = 10)
Run Code Online (Sandbox Code Playgroud)

所以只需按比例制作即可

在此输入图像描述


And*_*ele 6

使用对数刻度,只需使用指数而不是绝对值来指定坐标.因此,在此示例中,使用0 <x <1,因为比例从1e0到1e1:

p = qplot(1:10, 1:10, log='x')
g = ggplotGrob(qplot(1, 1))
p + annotation_custom(grob = g, xmin = 0.3, xmax = 0.9, ymin = 6, ymax = 10)
Run Code Online (Sandbox Code Playgroud)