2

这很愚蠢,我不能是唯一一个在将注释与 ggplot2 图形对齐时遇到问题的人。

我不能使用 gridBase,因为我正在尝试自动执行复杂且重复的绘图任务,因此我需要以编程方式获取坐标,并将它们作为参数传递以在绘制 grobs 之前进行注释。

ggplot 可以访问此信息。我也必须有办法做到这一点!

令我惊讶的是,ggplot2 一开始并没有刻意公开对清晰注释情节如此重要的事情。

4

2 回答 2

2

The coordinates - or x and y scales - are set when generating the final plot. Hadley used the term "training". This means that you have to have it plotted, either as a grob or to a device, before ggplot knows the scales.

Instead, you can explicitly tell ggplot the extend of the axis, either with coord_cartesian or xlim. For this, you can use the range and pretty functions to determine the extent together with some nice rounding.

于 2013-05-14T12:35:12.843 回答
0

您可以使用layer_scales(plot, i = 1L, j = 1L).

在这里查看以供参考

于 2020-01-08T01:15:53.933 回答