在 ggplot2_2.2.0 中,以前可以通过关闭剪切来在绘图边缘放置文本。但是,在使用 facets 的情况下,这似乎不再可能(但如果没有使用 facets,则仍然有效)。我在这里发布了一个问题here,但尚未解决。同时,如果有任何解决方法,请告知!以下是一个最小的(非)工作示例:
library(ggplot2)
library(grid)
df.plot = data.frame(x = 1, y = 1, facet = 'facet', stringsAsFactors = F)
df.text = data.frame(x = 1, y = -0.3, label = 'test', facet = 'facet', stringsAsFactors = F)
p = ggplot(df.plot,aes(x = x, y = y))+
facet_grid(~facet)+ # 'test' is only printed outside of the plot if faceting is turned off
geom_point()+
geom_text(data = df.text,aes(x=x,y=y,label=label))+
coord_cartesian(xlim = c(0, 2),ylim=c(0,2),expand=F)+
theme(plot.margin=unit(c(2,2,2,2),"cm"))
gt = ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name=="panel"] = "off"
grid.draw(gt)
gt$layout$clip[gt$layout$name=="panel-1-1"] = "off"
- hrbrmstrgt$layout$clip = "off"
。 - Tobi