感谢建议查看这个问题 https://stackoverflow.com/questions/56025382/ggrepel-labels-outside-to-the-right-of-ggplot-area/56027661#56027661 (and 这个问题 https://stackoverflow.com/questions/12409960/ggplot2-annotate-outside-of-plot让我知道coord_cartesian(clip = "off")
,我做了以下工作(note我必须改变geom_segment(x=0, ...)
to geom_segment(x=-Inf, ...)
在上面的基本示例中,这样关闭剪辑就不会弄乱事情)。
gg1 + coord_cartesian(clip = "off") +
theme(axis.text.y = element_blank(),
plot.margin = margin(t=5.5, r=5.5, b=5.5, l=30, unit="pt")) +
geom_text_repel(x = 0.85, aes(label = z, y = y),
direction = "y",
force_pull = 100,
hjust = -7,
xlim = c(0.8,1))
请注意,这可能需要对情节边缘和参数进行大量的处理geom_text_repel
(force
, force_pull
, hjust
, xlim
等)让它看起来正确......我仍然没有按照我想要的方式得到我的真实情节,但它已经接近了。 (有可能是x
and hjust
值在这里是多余的......)