所以设置是这样的:
dat <- data.frame(a = c("longnameonthelefthandside"), b = c(sample(10)))
p <- ggplot(dat, aes(b,a)) + geom_point() + xlab("label")
我可以通过将unit
对象传递给来调整 x 轴标签hjust
:
p + opts(axis.title.x=theme_text(size=12,hjust=unit(0.3,"npc")))
但是有一些关于添加单元对象(可能,根据 ?unit)我没有掌握:
u1 <- unit(0.5,"npc")
u2 <- unit(0.25,"npc")
p + opts(axis.title.x=theme_text(size=12,hjust=u1+u2))
产生以下错误:
Error in grid.Call("L_textBounds", as.graphicsAnnot(x$label), x$x, x$y, :
Polygon edge not found
In addition: Warning message:
In validDetails.text(x) : NAs introduced by coercion
作为进一步的背景,我试图通过 Baptiste 拼凑一个有点神秘的解决方法here